From ffa42dd200436bf38fe9b3adb6dbf30a1eaacdcd Mon Sep 17 00:00:00 2001 From: Jeremy Siek Date: Fri, 1 Dec 2000 00:57:49 +0000 Subject: [PATCH] changed how monoid identity element works [SVN r8374] --- include/boost/pending/concept_archetypes.hpp | 9 +++++---- stl_concept_covering.cpp | 20 +++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/include/boost/pending/concept_archetypes.hpp b/include/boost/pending/concept_archetypes.hpp index 7087077..e11d30a 100644 --- a/include/boost/pending/concept_archetypes.hpp +++ b/include/boost/pending/concept_archetypes.hpp @@ -36,6 +36,8 @@ namespace boost { friend void dummy_friend(); // just to avoid warnings }; + // This is a helper class that provides a way to get a reference to + // an object. template class static_object { public: @@ -104,8 +106,9 @@ namespace boost { 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. + // Careful, don't use same type for T and Base. That results in the + // conversion operator being invalid. Since T is often + // null_archetype, can't use null_archetype for Base. template class convertible_to_archetype : public Base { private: @@ -295,8 +298,6 @@ namespace boost { return Return(dummy_cons); \ } - // The default constructor used in Return() above is bad. - BOOST_DEFINE_BINARY_OPERATOR_ARCHETYPE(+, plus_op) BOOST_DEFINE_BINARY_OPERATOR_ARCHETYPE(*, time_op) BOOST_DEFINE_BINARY_OPERATOR_ARCHETYPE(/, divide_op) diff --git a/stl_concept_covering.cpp b/stl_concept_covering.cpp index 69c850e..a0eab59 100644 --- a/stl_concept_covering.cpp +++ b/stl_concept_covering.cpp @@ -109,13 +109,19 @@ namespace part_sum // for std::power -template -boost::multipliable_archetype -identity_element(std::multiplies< boost::multipliable_archetype >) { - return boost::multipliable_archetype(boost::dummy_cons); +namespace power_stuff { + struct monoid_archetype { + monoid_archetype(boost::detail::dummy_constructor x) { } + }; + + boost::multipliable_archetype + identity_element + (std::multiplies< boost::multipliable_archetype >) + { + return boost::multipliable_archetype(boost::dummy_cons); + } } - int main() { @@ -1075,12 +1081,12 @@ main() // SGI STL extension { int n = 1; - multipliable_archetype<> x(dummy_cons); + multipliable_archetype x(dummy_cons); x = std::power(x, n); } { int n = 1; - typedef multipliable_archetype<> T; + typedef multipliable_archetype T; T x(dummy_cons); x = std::power(x, n, multiplies()); }