diff --git a/include/boost/pending/concept_archetypes.hpp b/include/boost/pending/concept_archetypes.hpp index 44419d9..7087077 100644 --- a/include/boost/pending/concept_archetypes.hpp +++ b/include/boost/pending/concept_archetypes.hpp @@ -9,6 +9,7 @@ #define BOOST_CONCEPT_ARCHETYPES_HPP #include +#include namespace boost { @@ -99,21 +100,12 @@ namespace boost { sgi_assignable_archetype(const detail::dummy_constructor& x) : Base(x) { } }; -#if 0 - // Careful, don't use same type for T and Base. That - // results in the conversion operator being invalid. - template > - class convertible_to_archetype : public Base { - public: - convertible_to_archetype(detail::dummy_constructor x) : Base(x) { } - operator const T&() const { return static_object::get(); } - }; -#else - struct default_archetype_base { default_archetype_base(detail::dummy_constructor x) { } }; + // Careful, don't use same type for T and Base. That + // results in the conversion operator being invalid. template class convertible_to_archetype : public Base { private: @@ -125,7 +117,20 @@ namespace boost { convertible_to_archetype(detail::dummy_constructor x) : Base(x) { } operator const T&() const { return static_object::get(); } }; -#endif + + template + class convertible_from_archetype : public Base { + private: + convertible_from_archetype() { } + convertible_from_archetype(const convertible_from_archetype& ) { } + convertible_from_archetype& operator=(const convertible_from_archetype&) + { return *this; } + public: + convertible_from_archetype(detail::dummy_constructor x) : Base(x) { } + convertible_from_archetype(const T&) { } + convertible_from_archetype& operator=(const T&) + { return *this; } + }; class boolean_archetype { public: @@ -146,12 +151,12 @@ namespace boost { boolean_archetype operator==(const equality_comparable_archetype&, const equality_comparable_archetype&) - { return boolean_archetype(dummy_cons);; } + { return boolean_archetype(dummy_cons); } template boolean_archetype operator!=(const equality_comparable_archetype&, const equality_comparable_archetype&) - { return boolean_archetype(dummy_cons);; } + { return boolean_archetype(dummy_cons); } template > @@ -170,12 +175,12 @@ namespace boost { boolean_archetype operator==(const equality_comparable2_first_archetype&, const equality_comparable2_second_archetype&) - { return boolean_archetype(dummy_cons);; } + { return boolean_archetype(dummy_cons); } template boolean_archetype operator!=(const equality_comparable2_first_archetype&, const equality_comparable2_second_archetype&) - { return boolean_archetype(dummy_cons);; } + { return boolean_archetype(dummy_cons); } template > @@ -200,22 +205,22 @@ namespace boost { boolean_archetype operator<(const comparable_archetype&, const comparable_archetype&) - { return boolean_archetype(dummy_cons);; } + { return boolean_archetype(dummy_cons); } template boolean_archetype operator<=(const comparable_archetype&, const comparable_archetype&) - { return boolean_archetype(dummy_cons);; } + { return boolean_archetype(dummy_cons); } template boolean_archetype operator>(const comparable_archetype&, const comparable_archetype&) - { return boolean_archetype(dummy_cons);; } + { return boolean_archetype(dummy_cons); } template boolean_archetype operator>=(const comparable_archetype&, const comparable_archetype&) - { return boolean_archetype(dummy_cons);; } + { return boolean_archetype(dummy_cons); } #define BOOST_DEFINE_BINARY_PREDICATE_ARCHETYPE(OP, NAME) \ @@ -246,12 +251,41 @@ namespace boost { BOOST_DEFINE_BINARY_PREDICATE_ARCHETYPE(>, greater_than_op) BOOST_DEFINE_BINARY_PREDICATE_ARCHETYPE(>=, greater_equal_op) +#define BOOST_DEFINE_OPERATOR_ARCHETYPE(OP, NAME) \ + template > \ + class NAME##_archetype : public Base { \ + public: \ + NAME##_archetype(detail::dummy_constructor x) : Base(x) { } \ + NAME##_archetype(const NAME##_archetype&) \ + : Base(dummy_cons) { } \ + NAME##_archetype& operator=(const NAME##_archetype&) { return *this; } \ + }; \ + template \ + NAME##_archetype \ + operator OP (const NAME##_archetype&,\ + const NAME##_archetype&) \ + { return NAME##_archetype(dummy_cons); } + + BOOST_DEFINE_OPERATOR_ARCHETYPE(+, addable) + BOOST_DEFINE_OPERATOR_ARCHETYPE(-, subtractable) + BOOST_DEFINE_OPERATOR_ARCHETYPE(*, multipliable) + BOOST_DEFINE_OPERATOR_ARCHETYPE(/, dividable) + BOOST_DEFINE_OPERATOR_ARCHETYPE(%, modable) + + // As is, these are useless because of the return type. + // Need to invent a better way... #define BOOST_DEFINE_BINARY_OPERATOR_ARCHETYPE(OP, NAME) \ template > \ - class NAME##_first_archetype : public Base { }; \ + class NAME##_first_archetype : public Base { \ + public: \ + NAME##_first_archetype(detail::dummy_constructor x) : Base(x) { } \ + }; \ \ template > \ - class NAME##_second_archetype : public Base { }; \ + class NAME##_second_archetype : public Base { \ + public: \ + NAME##_second_archetype(detail::dummy_constructor x) : Base(x) { } \ + }; \ \ template \ Return \ @@ -318,7 +352,7 @@ namespace boost { } }; - template + template > class binary_predicate_archetype { typedef boolean_archetype Return; binary_predicate_archetype() { }