From cf068fba24aa68a7b3f62861675bbd9798ca4a24 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Tue, 6 Jan 2004 17:36:30 +0000 Subject: [PATCH] merged from trunk [SVN r21516] --- .../iterator/detail/minimum_category.hpp | 14 +- include/boost/iterator/indirect_iterator.hpp | 142 ++---------------- include/boost/iterator/iterator_concepts.hpp | 65 +++++--- test/Jamfile | 9 +- test/indirect_iterator_test.cpp | 19 ++- test/static_assert_same.hpp | 5 + test/zip_iterator_test.cpp | 1 + 7 files changed, 92 insertions(+), 163 deletions(-) diff --git a/include/boost/iterator/detail/minimum_category.hpp b/include/boost/iterator/detail/minimum_category.hpp index 50fe6f5..d56ab9a 100755 --- a/include/boost/iterator/detail/minimum_category.hpp +++ b/include/boost/iterator/detail/minimum_category.hpp @@ -21,7 +21,13 @@ namespace boost { namespace detail { // // template -struct minimum_category_impl; +struct minimum_category_impl +# if BOOST_WORKAROUND(BOOST_MSVC, == 1200) +{ + typedef void type; +} +# endif +; template struct error_not_related_by_convertibility; @@ -58,15 +64,9 @@ template <> struct minimum_category_impl { template struct apply -# if BOOST_WORKAROUND(BOOST_MSVC, == 1200) - { - typedef void type; - }; -# else : error_not_related_by_convertibility { }; -# endif }; template diff --git a/include/boost/iterator/indirect_iterator.hpp b/include/boost/iterator/indirect_iterator.hpp index 59babdf..91c4283 100644 --- a/include/boost/iterator/indirect_iterator.hpp +++ b/include/boost/iterator/indirect_iterator.hpp @@ -12,11 +12,15 @@ #include #include -#include - -#include +#include +#include +#include #include + +#include +#include + #include #include #include @@ -37,116 +41,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) - } - - 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_< - boost::python::detail::is_reference_to_const< - typename iterator_reference::type - > - > - { - }; - - 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 - template - struct default_indirect_value - { - typedef typename remove_cv< - typename referent::type - >::type referent_t; - - typedef typename mpl::if_< - mpl::or_< - class_has_element_type - , iterator_is_mutable - > - , referent_t - , referent_t const - >::type type; - }; - template struct indirect_base { @@ -156,10 +52,17 @@ namespace boost indirect_iterator , Iter , typename ia_dflt_help< - Value, default_indirect_value + Value, pointee >::type , Category - , Reference + , typename ia_dflt_help< + Reference + , mpl::apply_if< + is_same + , indirect_reference + , add_reference + > + >::type , Difference > type; }; @@ -168,19 +71,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. - template - struct referent - : mpl::apply_if< - detail::class_has_element_type - , detail::element_type - , iterator_value - > - {}; template < class Iterator diff --git a/include/boost/iterator/iterator_concepts.hpp b/include/boost/iterator/iterator_concepts.hpp index e67d371..93e0972 100644 --- a/include/boost/iterator/iterator_concepts.hpp +++ b/include/boost/iterator/iterator_concepts.hpp @@ -346,35 +346,50 @@ namespace detail } // namespace detail - template - class InteroperableConcept - { - public: - typedef typename boost::iterator_traversal::type traversal_category; - typedef typename boost::detail::iterator_traits::difference_type - difference_type; + template + class InteroperableConcept + { + public: + typedef typename boost::detail::pure_traversal_tag< + typename boost::iterator_traversal< + Iterator + >::type + >::type traversal_category; + + typedef typename + boost::detail::iterator_traits::difference_type + difference_type; - typedef typename boost::iterator_traversal::type - const_traversal_category; - typedef typename boost::detail::iterator_traits::difference_type - const_difference_type; + typedef typename boost::detail::pure_traversal_tag< + typename boost::iterator_traversal< + ConstIterator + >::type + >::type const_traversal_category; + + typedef typename + boost::detail::iterator_traits::difference_type + const_difference_type; - void constraints() { - BOOST_STATIC_ASSERT((boost::is_same< difference_type, - const_difference_type>::value)); - BOOST_STATIC_ASSERT((boost::is_same< traversal_category, - const_traversal_category>::value)); - - // ToDo check what the std really requires - - // detail::Operations::constraints(i, ci); + void constraints() + { + BOOST_STATIC_ASSERT( + (boost::is_same< difference_type, const_difference_type>::value) + ); + + BOOST_STATIC_ASSERT( + (boost::is_same< traversal_category, const_traversal_category>::value) + ); - ci = i; + // ToDo check what the std really requires - } - Iterator i; - ConstIterator ci; - }; + // detail::Operations::constraints(i, ci); + + ci = i; + + } + Iterator i; + ConstIterator ci; + }; } // namespace boost_concepts diff --git a/test/Jamfile b/test/Jamfile index 94a46d3..1cd2c81 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -18,7 +18,13 @@ test-suite iterator # compilation problems. [ run is_convertible_fail.cpp ] - [ run zip_iterator_test.cpp ] + [ run zip_iterator_test.cpp + : : : + + # stlport's debug mode generates long symbols which overwhelm + # vc6 + <*>release + ] # These tests should work for just about everything. [ compile is_lvalue_iterator.cpp ] @@ -31,6 +37,7 @@ test-suite iterator [ compile iterator_archetype_cc.cpp ] [ run transform_iterator_test.cpp ] [ run indirect_iterator_test.cpp ] + [ compile indirect_iterator_member_types.cpp ] [ run filter_iterator_test.cpp ] [ run reverse_iterator_test.cpp ] [ run counting_iterator_test.cpp ] diff --git a/test/indirect_iterator_test.cpp b/test/indirect_iterator_test.cpp index cad4091..56db69b 100644 --- a/test/indirect_iterator_test.cpp +++ b/test/indirect_iterator_test.cpp @@ -26,6 +26,8 @@ #include #include +#include + #include #include #include @@ -43,6 +45,9 @@ #endif +template struct see_type; +template struct see_val; + struct my_iterator_tag : public std::random_access_iterator_tag { }; using boost::dummyT; @@ -136,6 +141,10 @@ void more_indirect_iterator_tests() assert(std::equal(db, de, store.begin())); } +// element_type detector; defaults to true so the test passes when +// has_xxx isn't implemented +BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_element_type, element_type, true) + int main() { @@ -143,6 +152,10 @@ main() dummyT(3), dummyT(4), dummyT(5) }; const int N = sizeof(array)/sizeof(dummyT); +# if BOOST_WORKAROUND(BOOST_MSVC, == 1200) + boost::shared_ptr zz((dummyT*)0); // Why? I don't know, but it suppresses a bad instantiation. +# endif + typedef std::vector > shared_t; shared_t shared; @@ -151,9 +164,8 @@ main() typedef boost::indirect_iterator iter_t; BOOST_STATIC_ASSERT( - boost::detail::has_element_type< - boost::shared_ptr - // std::iterator_traits::value_type + has_element_type< + boost::detail::iterator_traits::value_type >::value ); @@ -195,7 +207,6 @@ main() const_indirect_iterator j(ptr); boost::random_access_iterator_test(j, N, array); - dummyT const*const* const_ptr = ptr; boost::random_access_iterator_test(boost::make_indirect_iterator(const_ptr), N, array); diff --git a/test/static_assert_same.hpp b/test/static_assert_same.hpp index e463192..0b4b04c 100644 --- a/test/static_assert_same.hpp +++ b/test/static_assert_same.hpp @@ -7,6 +7,7 @@ # define STATIC_ASSERT_SAME_DWA2003530_HPP # include +# include #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION template @@ -32,4 +33,8 @@ struct static_assert_same {}; #endif +#define STATIC_ASSERT_SAME( T1,T2 ) \ + enum { BOOST_JOIN(boost_static_assert_enum_, __LINE__) \ + = static_assert_same::value } + #endif // STATIC_ASSERT_SAME_DWA2003530_HPP diff --git a/test/zip_iterator_test.cpp b/test/zip_iterator_test.cpp index f33dbd9..274f7ac 100755 --- a/test/zip_iterator_test.cpp +++ b/test/zip_iterator_test.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include