From 1fca93be10327ef90487c61c4943426ee3fae3a1 Mon Sep 17 00:00:00 2001 From: Jeremy Siek Date: Sun, 4 Jan 2004 18:44:29 +0000 Subject: [PATCH] first stab at simplified version [SVN r21482] --- doc/indirect_iterator_ref.rst | 7 +- include/boost/iterator/indirect_iterator.hpp | 157 +++---------------- 2 files changed, 26 insertions(+), 138 deletions(-) diff --git a/doc/indirect_iterator_ref.rst b/doc/indirect_iterator_ref.rst index 1d6e477..21f90d9 100644 --- a/doc/indirect_iterator_ref.rst +++ b/doc/indirect_iterator_ref.rst @@ -42,12 +42,15 @@ following pseudo-code. We use the abbreviation typedef remove_const::type value_type; if (Reference is use_default) then - typedef iterator_traits::reference reference; + if (Value is use_default) then + typedef iterator_traits::reference reference; + else + typedef Value& reference; else typedef Reference reference; if (Value is use_default) then - typedef iterator_traits::pointer pointer; + typedef ?? pointer; else typedef Value* pointer; diff --git a/include/boost/iterator/indirect_iterator.hpp b/include/boost/iterator/indirect_iterator.hpp index b023a06..d2b7351 100644 --- a/include/boost/iterator/indirect_iterator.hpp +++ b/include/boost/iterator/indirect_iterator.hpp @@ -37,63 +37,8 @@ namespace boost template class indirect_iterator; - template - struct referent; - namespace detail { - struct unspecified {}; - - // - // Detection for whether a type has a nested `element_type' - // typedef. Used to detect smart pointers. For compilers not - // supporting mpl's has_xxx, we supply specializations. However, we - // really ought to have a specializable is_pointer template which - // can be used instead with something like - // boost/python/pointee.hpp to find the value_type. - // -# ifndef BOOST_MPL_NO_AUX_HAS_XXX - namespace aux - { - BOOST_MPL_HAS_XXX_TRAIT_DEF(element_type) - BOOST_MPL_HAS_XXX_TRAIT_DEF(type) - } - - template - struct has_element_type - : mpl::bool_< - mpl::if_< - is_class - , ::boost::detail::aux::has_element_type - , mpl::false_ - >::type::value - > - { - }; -# else - template - struct has_element_type - : mpl::false_ {}; - - template - struct has_element_type > - : mpl::true_ {}; - - template - struct has_element_type > - : mpl::true_ {}; - - template - struct has_element_type > - : mpl::true_ {}; -# endif - - // Metafunction accessing the nested ::element_type - template - struct element_type - : mpl::identity - {}; - template struct iterator_is_mutable : mpl::not_< @@ -104,65 +49,31 @@ namespace boost { }; - template - struct not_int_impl - { - template - struct apply { - typedef T type; - }; - }; - - template <> - struct not_int_impl {}; - - template - 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 + // to deduce the default type template struct default_indirect_value { -#if 0 - typedef typename remove_cv< - typename referent::type - >::type referent_t; - typedef typename mpl::if_< - mpl::or_< - class_has_element_type - , iterator_is_mutable // This doesn't work when Dereferencable is not an iterator. -JGS - > - , referent_t - , referent_t const - >::type type; -#else - template - struct get_from_iter { - typedef typename mpl::if_< iterator_is_mutable - , typename iterator_value::type - , typename iterator_value::type const - >::type type; - }; + , typename iterator_value::type + , typename iterator_value::type const + >::type type; + }; - typedef typename mpl::apply_if< - aux::has_type< referent > - , referent - , get_from_iter - >::type type; -#endif + // If the Reference parameter is unspecified, we use this metafunction + // to deduce the default type + template + struct default_indirect_reference + { + struct use_value_ref { typedef Value& type; }; + + typedef typename + mpl::apply_if< + is_same + , iterator_reference + , use_value_ref + >::type type; }; template @@ -177,7 +88,9 @@ namespace boost Value, default_indirect_value >::type , Category - , Reference + , typename ia_dflt_help< + Reference, default_indirect_reference + >::type , Difference > type; }; @@ -186,34 +99,6 @@ 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. -#if 0 - template - struct referent - : mpl::apply_if< - detail::class_has_element_type - , detail::element_type - , iterator_value - > - {}; -#else - namespace detail { - struct has_no_type { }; - } - template - struct referent - : mpl::if_< - detail::class_has_element_type - , detail::element_type - , detail::has_no_type - >::type - {}; - -#endif template < class Iterator