From 3fe0d4b5322e6476b5dd0a0f09f707549ed932b2 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Wed, 16 Jul 2003 19:35:46 +0000 Subject: [PATCH] * Use boost::referent<> metafunction for detecting the value type of indirect_iterator. * Change the order of tests in the Jamfile so expected failures come last, accounting for some recent Boost.Build change I suppose. [SVN r19158] --- include/boost/iterator/indirect_iterator.hpp | 77 ++++++++++++++------ test/Jamfile | 15 +++- 2 files changed, 65 insertions(+), 27 deletions(-) diff --git a/include/boost/iterator/indirect_iterator.hpp b/include/boost/iterator/indirect_iterator.hpp index 4e2500b..0839072 100644 --- a/include/boost/iterator/indirect_iterator.hpp +++ b/include/boost/iterator/indirect_iterator.hpp @@ -14,7 +14,12 @@ #include +#include + #include +#include +#include +#include #include #include @@ -32,6 +37,9 @@ namespace boost template struct indirect_iterator; + template + struct referent; + namespace detail { struct unspecified {}; @@ -79,9 +87,10 @@ namespace boost : mpl::true_ {}; # endif - // Metafunction returning the nested element_type typedef + // Metafunction accessing the nested ::element_type template - struct smart_pointer_value : remove_const + struct element_type + : mpl::identity {}; template @@ -110,37 +119,45 @@ namespace boost struct not_int : not_int_impl::template apply {}; + + template + struct class_has_element_type + : mpl::and_< + is_class + , has_element_type + > + {}; + // If the Value parameter is unspecified, we use this metafunction // to deduce the default types - template - struct indirect_base + template + struct default_indirect_value { - typedef typename iterator_value::type dereferenceable; - - typedef mpl::and_< - is_class - , has_element_type - > is_smart_ptr; - - typedef typename mpl::apply_if< - is_smart_ptr - , smart_pointer_value - , iterator_value - >::type value_type; + typedef typename remove_cv< + typename referent::type + >::type referent_t; typedef typename mpl::if_< mpl::or_< - is_smart_ptr - , iterator_is_mutable + class_has_element_type + , iterator_is_mutable > - , value_type - , value_type const - >::type cv_value_type; - + , referent_t + , referent_t const + >::type type; + }; + + template + struct indirect_base + { + typedef typename iterator_traits::value_type dereferenceable; + typedef iterator_adaptor< indirect_iterator , Iter - , cv_value_type + , typename ia_dflt_help< + Value, default_indirect_value + >::type , Category , Reference , Difference @@ -151,6 +168,20 @@ namespace boost struct indirect_base {}; } // namespace detail + // User-specializable metafunction which returns the referent of a + // dereferenceable type. The default implementation returns + // Dereferenceable::element_type if such a member exists (thus + // handling the boost smart pointers and auto_ptr), and + // iterator_traits::value_type otherwise. + template + struct referent + : mpl::apply_if< + detail::class_has_element_type + , detail::element_type + , iterator_value + > + {}; + template < class Iterator , class Value = use_default diff --git a/test/Jamfile b/test/Jamfile index f00e2cb..a4672aa 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -10,7 +10,17 @@ SEARCH on testing.jam = $(BOOST_BUILD_PATH) ; include testing.jam ; test-suite iterator - : [ run unit_tests.cpp ] + : + # These first two tests will run last, and are expected to fail + # for many less-capable compilers. + + [ compile-fail interoperable_fail.cpp ] + # test uses expected success, so that we catch unrelated + # compilation problems. + [ run is_convertible_fail.cpp ] + + # These tests should work for just about everything. + [ run unit_tests.cpp ] [ run concept_tests.cpp ] [ run iterator_adaptor_cc.cpp ] [ run iterator_adaptor_test.cpp ] @@ -30,7 +40,4 @@ test-suite iterator [ run ../../utility/reverse_iterator_example.cpp ] [ run ../../utility/transform_iterator_example.cpp ] - [ run is_convertible_fail.cpp ] # test changed to expected success, so that we catch compilation failures. - - [ compile-fail interoperable_fail.cpp ] ;