Index: creating_concepts.htm
===================================================================
--- creating_concepts.htm (revision 74469)
+++ creating_concepts.htm (working copy)
@@ -1,4 +1,4 @@
-
@@ -47,22 +47,16 @@
BOOST_CONCEPT_USAGE(InputIterator)
{
- X j(i); // require copy construction
- same_type(*i++,v); // require postincrement-dereference returning value_type
- X& x = ++j; // require postincrement-dereference returning convertible to value_type
+ X& x = ++j; // require preincrement returning X&
}
private:
X i;
- value_type v;
-
- // Type deduction will fail unless the arguments have the same type.
- template <typename T>
- void same_type(T const&, T const&);
};
@@ -87,35 +81,32 @@
BOOST_CONCEPT_USAGE
macro to declare the function that
exercises all the concept's valid expressions. Note that at this point you
may sometimes need to be a little creative: for example, to check that
- *i++
returns the iterator's value type, we pass both values to
- the same_type
member function template, which requires both
- arguments to have the same type, modulo references and cv-qualification.
- It's an imperfect check, but it's better than nothing.
*i++
returns something convertible to the iterator's value type,
+ we use it to initialize a variable of type value_type
.
You may be wondering why we declared i
and v
- as data members in the example above. Why didn't we simply write the
+
You may be wondering why we declared i
+ as a data member in the example above. Why didn't we simply write the
following?
BOOST_CONCEPT_USAGE(InputIterator) { - X i; // create the values we need - value_type v; - X j(i); // require copy construction - same_type(*i++,v); // require postincrement-dereference returning value_type - X& x = ++j; // require postincrement-dereference returning convertible to value_type + X& x = ++j; // require preincrement returning X& }
Unfortunately, that code wouldn't have worked out so well, because it
- unintentionally imposes the requirement that X
and its value
- type are both default-constructible. On the other hand, since instances of
+ unintentionally imposes the requirement that X
is
+ default-constructible. On the other hand, since instances of
the InputIterator
template will never be constructed, the
compiler never has to check how its data members will be constructed (C++
Standard Section 14.7.1 9). For that reason you should always