|
Boost : |
From: Yitzhak Sapir (yitzhaks_at_[hidden])
Date: 2002-09-05 15:35:33
On Thu, 5 Sep 2002, David Abrahams wrote:
> From: "Yitzhak Sapir" <yitzhaks_at_[hidden]>
>
> <<The attached patch solves it using inheritance (operator[] is inherited,
> with the inherited class chosen based on Category), but is much more
> complex than the above trick would have been.>>
>
> Does it pass all the regression tests?
No. But the following patch almost does (for MSVC and MSVC+STLPort):
Given:
run libs/utility/counting_iterator_test.cpp
run libs/utility/iterator_adaptor_test.cpp
run libs/utility/transform_iterator_test.cpp
run libs/utility/indirect_iterator_test.cpp
run libs/utility/iter_traits_gen_test.cpp
compile-fail libs/utility/iter_adaptor_fail_expected1.cpp
compile-fail libs/utility/iter_adaptor_fail_expected2.cpp
run libs/utility/iterator_traits_test.cpp
run libs/utility/iterators_test.cpp
It fails for iterators_test.cpp alone:
*** libs/utility/iterators_test.cpp ***
** Microsoft Visual C++
cl /Feboosttmp.exe /nologo /Zm400 /MDd /W3 /GR /GX /Zi /Od /GZ /I".." /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_CONSOLE" ../libs/utility/iterators_test.cpp /link /incremental:no user32.lib
iterators_test.cpp
..\boost/test/unit_test_log.hpp(20) : fatal error C1083: Cannot open include file: 'boost/test/detail/unit_test_config.hpp': No such file or directory
0.14 s
Return code: 2
Fail
** Microsoft Visual C++ with STLport
cl /Feboosttmp.exe /nologo /Zm400 /MDd /W3 /GR /GX /Zi /Od /GZ /I "$BOOST_STLPORT_PATH/include/stlport" /I".." /D "__STL_DEBUG" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_CONSOLE" ../libs/utility/iterators_test.cpp /link /incremental:no user32.lib
iterators_test.cpp
..\boost/test/unit_test_log.hpp(20) : fatal error C1083: Cannot open include file: 'boost/test/detail/unit_test_config.hpp': No such file or directory
0.05 s
Return code: 2
Fail
cvs -z9 -Q diff -c boost/iterator_adaptors.hpp
Index: boost/iterator_adaptors.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/iterator_adaptors.hpp,v
retrieving revision 1.65
diff -c -r1.65 iterator_adaptors.hpp
*** boost/iterator_adaptors.hpp 8 Aug 2002 16:42:18 -0000 1.65
--- boost/iterator_adaptors.hpp 5 Sep 2002 19:24:36 -0000
***************
*** 557,562 ****
--- 557,565 ----
typedef detail::cons_type<detail::iterator_category_tag, IteratorCategory> type;
};
+ template <class Base, class Policies, class Value, class Reference, class Pointer, class Category, class Distance>
+ struct iterator_adaptor;
+
namespace detail {
struct end_of_list { };
***************
*** 761,769 ****
BOOST_STATIC_ASSERT(forward_iter_with_real_reference);
};
- } // namespace detail
// This macro definition is only temporary in this file
# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300
--- 764,866 ----
BOOST_STATIC_ASSERT(forward_iter_with_real_reference);
};
+ struct non_random_access_index_iterator_base
+ {
+ template <class Base, class Policies, class Value, class Reference, class Pointer, class Category, class Distance>
+ struct index_base_type
+ : detail::iterator_adaptor_traits_gen<Base,Value,Reference,Pointer,Category,Distance>::type
+ {
+ protected:
+ typedef iterator_adaptor<Base,Policies,Value,Reference,Pointer,Category,Distance> self;
+ public:
+ typedef detail::iterator_adaptor_traits_gen<Base,Value,Reference,Pointer,Category,Distance> TraitsGen;
+ typedef typename TraitsGen::type Traits;
+
+ typedef typename Traits::difference_type difference_type;
+ typedef typename Traits::value_type value_type;
+ typedef typename Traits::pointer pointer;
+ typedef typename Traits::reference reference;
+ typedef typename Traits::iterator_category iterator_category;
+
+ typedef Base base_type;
+ typedef Policies policies_type;
+ };
+ };
+
+ struct random_access_index_iterator_base
+ {
+ template <class Base, class Policies, class Value, class Reference, class Pointer, class Category, class Distance>
+ struct index_base_type
+ : detail::iterator_adaptor_traits_gen<Base,Value,Reference,Pointer,Category,Distance>::type
+ {
+ protected:
+ typedef iterator_adaptor<Base,Policies,Value,Reference,Pointer,Category,Distance> self;
+ public:
+ typedef detail::iterator_adaptor_traits_gen<Base,Value,Reference,Pointer,Category,Distance> TraitsGen;
+ typedef typename TraitsGen::type Traits;
+
+ typedef typename Traits::difference_type difference_type;
+ typedef typename Traits::value_type value_type;
+ typedef typename Traits::pointer pointer;
+ typedef typename Traits::reference reference;
+ typedef typename Traits::iterator_category iterator_category;
+
+ typedef Base base_type;
+ typedef Policies policies_type;
+
+ value_type operator[](difference_type n) const
+ { return *(*static_cast<const iterator_adaptor<Base,Policies,Value,Reference,Pointer,Category, Distance>*>(this) + n); }
+ };
+ };
+
+ template <class Category> struct index_category_chooser
+ {
+ struct iterator_base
+ {
+ template <class Base, class Policies, class Value, class Reference, class Pointer, class Category, class Distance>
+ struct index_base_type;
+ };
+ };
+
+ template<> struct index_category_chooser<std::input_iterator_tag>
+ {
+ typedef non_random_access_index_iterator_base iterator_base;
+ };
+ template<> struct index_category_chooser<std::output_iterator_tag>
+ {
+ typedef non_random_access_index_iterator_base iterator_base;
+ };
+
+ template<> struct index_category_chooser<std::forward_iterator_tag>
+ {
+ typedef non_random_access_index_iterator_base iterator_base;
+ };
+
+ template<> struct index_category_chooser<std::bidirectional_iterator_tag>
+ {
+ typedef non_random_access_index_iterator_base iterator_base;
+ };
+
+ template<> struct index_category_chooser<std::random_access_iterator_tag>
+ {
+ typedef random_access_index_iterator_base iterator_base;
+ // typedef non_random_access_index_iterator_base iterator_base;
+ };
+
+ template <class Base, class Policies, class Value, class Reference, class Pointer, class Category, class Distance>
+ struct index_iterator_impl
+ {
+ typedef detail::iterator_adaptor_traits_gen<Base,Value,Reference,Pointer,Category,Distance> TraitsGen;
+ typedef typename TraitsGen::type Traits;
+
+ typedef typename Traits::iterator_category iterator_category;
+ typedef index_category_chooser<iterator_category>::iterator_base iterator_base_generator;
+ typedef iterator_base_generator::index_base_type<Base,Policies,Value,Reference,Pointer,Category,Distance> type;
+ };
+
+ } // namespace detail
// This macro definition is only temporary in this file
# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300
***************
*** 811,835 ****
#ifdef BOOST_RELOPS_AMBIGUITY_BUG
iterator_comparisons<
iterator_adaptor<Base,Policies,Value,Reference,Pointer,Category,Distance>,
! typename detail::iterator_adaptor_traits_gen<Base,Value,Reference,Pointer,Category, Distance>::type
>
#else
! detail::iterator_adaptor_traits_gen<Base,Value,Reference,Pointer,Category,Distance>::type
#endif
{
! typedef iterator_adaptor<Base,Policies,Value,Reference,Pointer,Category,Distance> self;
public:
! typedef detail::iterator_adaptor_traits_gen<Base,Value,Reference,Pointer,Category,Distance> TraitsGen;
! typedef typename TraitsGen::type Traits;
! typedef typename Traits::difference_type difference_type;
! typedef typename Traits::value_type value_type;
! typedef typename Traits::pointer pointer;
! typedef typename Traits::reference reference;
! typedef typename Traits::iterator_category iterator_category;
! typedef Base base_type;
! typedef Policies policies_type;
private:
typedef detail::validator<
--- 908,934 ----
#ifdef BOOST_RELOPS_AMBIGUITY_BUG
iterator_comparisons<
iterator_adaptor<Base,Policies,Value,Reference,Pointer,Category,Distance>,
! typename detail::index_iterator_impl<Base,Policies,Value,Reference,Pointer,Category, Distance>::type
>
#else
! detail::index_iterator_impl<Base,Policies,Value,Reference,Pointer,Category,Distance>::type
#endif
{
! typedef detail::index_iterator_impl<Base,Policies,Value,Reference,Pointer,Category,Distance>::type
! index_base_type;
! typedef typename index_base_type::self self;
public:
! typedef index_base_type::TraitsGen TraitsGen;
! typedef index_base_type::Traits Traits;
! typedef typename index_base_type::difference_type difference_type;
! typedef typename index_base_type::value_type value_type;
! typedef typename index_base_type::pointer pointer;
! typedef typename index_base_type::reference reference;
! typedef typename index_base_type::iterator_category iterator_category;
! typedef index_base_type::base_type base_type;
! typedef index_base_type::policies_type policies_type;
private:
typedef detail::validator<
***************
*** 879,887 ****
#ifdef BOOST_MSVC
# pragma warning(pop)
#endif
-
- value_type operator[](difference_type n) const
- { return *(*this + n); }
self& operator++() {
#if !defined(__MWERKS__) || __MWERKS__ >= 0x2405
--- 978,983 ----
*****CVS exited normally with code 1*****
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk