If I write code (for example a custom container) that should satisfy a specific concept (for example an InputIterator
), I have to write much boilerplate (for example method/operator signatures and typedefs) to get started (write method/operator bodies and types in typedefs). This boilerplate code could be generated by a tool and I only have to fill gaps or change some parts.
The following is an excerpt of the Iterator
concept (reference):
Requirements
The type
It
satisfiesIterator
if
- The type
It
satisfiesCopyConstructible
, and- The type
It
satisfiesCopyAssignable
, and- The type
It
satisfiesDestructible
, and- lvalues of type
It
satisfySwappable
, andstd::iterator_traits<It>
has member typedefsvalue_type
,difference_type
,reference
,pointer
, anditerator_category
, andGiven
- r, an lvalue of type
It
.The following expressions must be valid and have their specified effects:
| **Expression** | **Return Type** | **Precondition** |
|----------------|-----------------|--------------------------------------------------------------------------|
| `*r` | unspecified | **r** is dereferenceable (see below) |
|----------------|-----------------|--------------------------------------------------------------------------|
| `++r` | `It&` | **r** is incrementable (the behavior of the expression `++r` is defined) |
A tool could generate code that looks something like this:
template <typename T>
class my_iterator {
public:
typedef my_iterator<T> self_type;
typedef std::input_iterator_tag iterator_category;
typedef T value_type;
typedef T & reference;
typedef T * pointer;
reference operator*() const
{
// TODO
}
self_type operator++()
{
// TODO
}
// ...
// more operator and method stubs of required concepts
// ...
}
How can I generate such code? Which tool can I use? In the Java-World, the IDE Eclipse can "implement interfaces" (create method stubs). Is there any C++ IDE that supports a similar feature for concepts? Or are there maybe any (predefined) code snippets I can use for this purpose?
ForwardIterator
implementation and like to extend it to aRandomAccessIterator
then I don't like to generate code that already exists in myForwardIterator
implementation. However, snippets sound easier to implement since they don't need static code analysis.