fixes and cleanups

[SVN r1141]
This commit is contained in:
Dave Abrahams
2003-04-10 13:40:42 +00:00
parent c1e5d7e331
commit aa0a32aa33
13 changed files with 218 additions and 137 deletions

View File

@@ -8,21 +8,22 @@
#define BOOST_ITERATOR_DETAIL_CATEGORIES_HPP
#include <boost/config.hpp>
#include <boost/iterator/detail/config_def.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/type_traits/is_base_and_derived.hpp>
#include <boost/type_traits/is_convertible.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/apply_if.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/or.hpp>
#include <boost/mpl/and.hpp>
#include <iterator>
#if BOOST_WORKAROUND(__MWERKS__, <=0x2407)
# define BOOST_NO_IS_CONVERTIBLE // "Convertible does not provide enough/is not working"
#endif
#include <iterator>
namespace boost
{
@@ -296,8 +297,6 @@ namespace boost
} // namespace boost
#ifdef BOOST_NO_IS_CONVERTIBLE
# undef BOOST_NO_IS_CONVERTIBLE
#endif
#include <boost/iterator/detail/config_undef.hpp>
#endif // BOOST_ITERATOR_DETAIL_CATEGORIES_HPP

View File

@@ -18,26 +18,81 @@
#include <boost/config.hpp> // for prior
#include <boost/detail/workaround.hpp>
#define BOOST_ITERATOR_CONFIG_DEF // if you get an error here, you have nested config_def #inclusion.
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) \
|| BOOST_WORKAROUND(__GNUC__, <= 2 && __GNUC_MINOR__ <= 95) \
|| BOOST_WORKAROUND(__MWERKS__, <= 0x3000)
|| BOOST_WORKAROUND(__MWERKS__, <= 0x3000) \
|| BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
# define BOOST_NO_SFINAE // "Substitution Failure Is Not An Error not implemented"
# if 0 // test code
template <bool x>
struct bar
{
typedef int type;
};
template <>
struct bar<false>
{
};
template <class T>
struct foo : bar<(sizeof(T) == 1)>
{
};
template <class T>
char* f(int, typename foo<T>::type = 0) { return 0; }
template <class T>
int f(...) { return 0; }
char* x = f<char>(0);
int y = f<char[2]>(0);
int main()
{
return 0;
}
# endif
#if BOOST_WORKAROUND(BOOST_MSVC, <=1200)
# define BOOST_ARG_DEP_TYPENAME
#else
# define BOOST_ARG_DEP_TYPENAME typename
#endif
#if BOOST_WORKAROUND(__MWERKS__, <=0x2407)
# define BOOST_NO_IS_CONVERTIBLE // "is_convertible doesn't always work"
# define BOOST_NO_IS_CONVERTIBLE // "is_convertible doesn't work for simple types"
#endif
#if BOOST_WORKAROUND(__GNUC__, BOOST_TESTED_AT(3)) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
# define BOOST_NO_IS_CONVERTIBLE_TEMPLATE // The following program fails to compile:
# if 0 // test code
template <class T>
struct foo
{
foo(T);
template <class U>
foo(foo<U> const& other) : p(other.p) { }
T p;
};
bool x = boost::is_convertible<foo<int const*>, foo<int*> >::value;
# endif
#endif
#if BOOST_WORKAROUND(__GNUC__, == 2 && __GNUC_MINOR__ == 95) \
|| BOOST_WORKAROUND(__MWERKS__, <= 0x2407) \
|| BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
# define BOOST_NO_MPL_AUX_HAS_XXX // "MPL's has_xxx facility doesn't work"
# define BOOST_ITERATOR_NO_MPL_AUX_HAS_XXX // "MPL's has_xxx facility doesn't work"
#endif
#if defined(BOOST_NO_SFINAE) || defined(BOOST_NO_IS_CONVERTIBLE) || defined(BOOST_NO_IS_CONVERTIBLE_TEMPLATE)
# define BOOST_NO_STRICT_ITERATOR_INTEROPERABILITY
#endif
// no include guard multiple inclusion intended

View File

@@ -14,7 +14,12 @@
//
#undef BOOST_NO_SFINAE
# undef BOOST_ARG_DEP_TYPENAME
#undef BOOST_NO_IS_CONVERTIBLE
# undef BOOST_NO_MPL_AUX_HAS_XXX
#undef BOOST_NO_IS_CONVERTIBLE_TEMPLATE
#undef BOOST_NO_STRICT_ITERATOR_INTEROPERABILITY
#ifdef BOOST_ITERATOR_CONFIG_DEF
# undef BOOST_ITERATOR_CONFIG_DEF
#else
# error missing or nested #include config_def
#endif

View File

@@ -12,11 +12,11 @@
#include <boost/iterator.hpp>
#include <boost/iterator/iterator_adaptor.hpp>
#include <boost/iterator/detail/config_def.hpp>
#include <boost/iterator/iterator_traits.hpp>
#include <boost/python/detail/indirect_traits.hpp>
#include <boost/mpl/not.hpp>
#include <boost/mpl/aux_/has_xxx.hpp>
#ifdef BOOST_NO_MPL_AUX_HAS_XXX
# include <boost/shared_ptr.hpp>
@@ -25,6 +25,8 @@
# include <memory>
#endif
#include <boost/iterator/detail/config_def.hpp> // must be last #include
namespace boost
{
template <class Iter, class Value, class Category, class Reference, class Pointer, class Difference>
@@ -42,7 +44,7 @@ namespace boost
// can be used instead with something like
// boost/python/pointee.hpp to find the value_type.
//
# if !defined BOOST_NO_MPL_AUX_HAS_XXX
# ifndef BOOST_NO_MPL_AUX_HAS_XXX
namespace aux
{
BOOST_MPL_HAS_XXX_TRAIT_DEF(element_type)
@@ -160,21 +162,11 @@ namespace boost
>
class indirect_iterator
: public detail::indirect_base<
Iterator
, Value
, Category
, Reference
, Pointer
, Difference
Iterator, Value, Category, Reference, Pointer, Difference
>::type
{
typedef typename detail::indirect_base<
Iterator
, Value
, Category
, Reference
, Pointer
, Difference
Iterator, Value, Category, Reference, Pointer, Difference
>::type super_t;
friend class iterator_core_access;
@@ -185,11 +177,15 @@ namespace boost
indirect_iterator(Iterator iter)
: super_t(iter) {}
template <class OtherIterator,
class OtherTraits>
template <
class Iterator2, class Value2, class Category2
, class Reference2, class Pointer2, class Difference2
>
indirect_iterator(
indirect_iterator<OtherIterator, OtherTraits> const& y
, typename enable_if_convertible<OtherIterator, Iterator>::type* = 0
indirect_iterator<
Iterator2, Value2, Category2, Reference2, Pointer2, Difference2
> const& y
, typename enable_if_convertible<Iterator2, Iterator>::type* = 0
)
: super_t(y.base())
{}
@@ -203,7 +199,6 @@ namespace boost
return **this->base();
# endif
}
};
template <class Iter>

View File

@@ -14,7 +14,7 @@
# include <boost/type_traits/is_convertible.hpp>
#include <boost/iterator/detail/config_def.hpp>
# include <boost/iterator/detail/config_def.hpp> // must appear last
namespace boost
{
@@ -35,7 +35,7 @@ namespace boost
//
template <typename A, typename B>
struct is_interoperable
#if defined(BOOST_NO_IS_CONVERTIBLE)
# ifdef BOOST_NO_STRICT_ITERATOR_INTEROPERABILITY
: mpl::true_
# else
: mpl::or_<

View File

@@ -97,29 +97,40 @@ namespace boost
// false positives for user/library defined iterator types. See comments
// on operator implementation for consequences.
//
template<
typename From
, typename To>
# if defined(BOOST_NO_IS_CONVERTIBLE) || defined(BOOST_NO_SFINAE)
template <class From, class To>
struct enable_if_convertible
{
// Borland 551 and vc6 have a problem with the use of base class
// forwarding in this template, so we write it all out here
# if defined(BOOST_NO_IS_CONVERTIBLE) || defined(BOOST_NO_SFINAE)
typedef detail::enable_type type;
# else
typedef typename detail::enable_if<
# if BOOST_WORKAROUND(_MSC_FULL_VER, BOOST_TESTED_AT(13102292) && BOOST_MSVC > 1300)
// For some reason vc7.1 needs us to "cut off" instantiation
// of is_convertible in the case where From == To.
mpl::or_<is_same<From,To>, is_convertible<From, To> >
# else
::boost::is_convertible<From, To>
# endif
, detail::enable_type
>::type type;
# endif
};
# elif BOOST_WORKAROUND(_MSC_FULL_VER, BOOST_TESTED_AT(13102292)) && BOOST_MSVC > 1300
// For some reason vc7.1 needs us to "cut off" instantiation
// of is_convertible in a few cases.
template<typename From, typename To>
struct enable_if_convertible
: detail::enable_if<
mpl::or_<
is_same<From,To>
, is_convertible<From, To>
>
, detail::enable_type
>
{};
# else
template<typename From, typename To>
struct enable_if_convertible
: detail::enable_if<
is_convertible<From, To>
, detail::enable_type
>
{};
# endif
//
// iterator_traits_adaptor can be used to create new iterator traits by adapting

View File

@@ -20,9 +20,11 @@
#include <boost/type_traits/is_convertible.hpp>
#include <boost/iterator/iterator_traits.hpp>
#include <boost/iterator/detail/config_def.hpp>
#include <boost/mpl/apply_if.hpp>
#include <boost/mpl/or.hpp>
#include <boost/iterator/detail/config_def.hpp> // this goes last
namespace boost
{
@@ -44,12 +46,17 @@ namespace boost
, class Return
>
struct enable_if_interoperable
#ifndef BOOST_NO_STRICT_ITERATOR_INTEROPERABILITY
: ::boost::detail::enable_if<
mpl::or_<
is_convertible<Facade1, Facade2>
, is_convertible<Facade2, Facade1>
>
, Return
>
#endif
{
# if BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
#ifdef BOOST_NO_STRICT_ITERATOR_INTEROPERABILITY
typedef Return type;
#endif
};
@@ -483,8 +490,8 @@ namespace boost
-
, typename Derived1::difference_type
, (is_same<
BOOST_ARG_DEP_TYPENAME Derived1::difference_type
, BOOST_ARG_DEP_TYPENAME Derived2::difference_type
BOOST_DEDUCED_TYPENAME Derived1::difference_type
, BOOST_DEDUCED_TYPENAME Derived2::difference_type
>::value)
, return
, distance_to )

View File

@@ -45,8 +45,8 @@ void readable_iterator_test(const Iterator i1, T v)
T v2 = r2;
assert(v1 == v);
assert(v2 == v);
typename access_category<Iterator>::type result_category;
is_readable(result_category);
typedef typename access_category<Iterator>::type result_category;
is_readable(result_category());
}
template <class Iterator, class T>

View File

@@ -38,7 +38,8 @@ namespace boost
reverse_iterator<OtherIterator> const& r
, typename enable_if_convertible<OtherIterator, Iterator>::type* = 0
)
: super_t(r.base()) {}
: super_t(r.base())
{}
private:
typename super_t::reference dereference() const { return *boost::prior(this->base()); }

View File

@@ -2,9 +2,11 @@ SEARCH on testing.jam = $(BOOST_BUILD_PATH) ;
include testing.jam ;
run concept_tests.cpp ;
run iterator_adaptor_cc.cpp ;
run counting_iterator_test.cpp ;
run iterator_adaptor_test.cpp ;
run transform_iterator_test.cpp ;
run indirect_iterator_test.cpp ;
run filter_iterator_test.cpp ;
run reverse_iterator_test.cpp ;
run counting_iterator_test.cpp ;
run is_convertible_fail.cpp ; # test changed to expected success, so that we catch compilation failures.
compile-fail interoperable_fail.cpp ;
compile-fail is_convertible_fail.cpp ;

View File

@@ -1,15 +1,11 @@
#include <boost/iterator/reverse_iterator.hpp>
#include <boost/static_assert.hpp>
#include <boost/cstdlib.hpp>
int main()
{
{
typedef boost::reverse_iterator<int*> rev_iter1;
typedef boost::reverse_iterator<char*> rev_iter2;
BOOST_STATIC_ASSERT((boost::is_convertible<rev_iter1, rev_iter2>::value));
}
return boost::exit_success;
return boost::is_convertible<rev_iter1, rev_iter2>::value
? boost::exit_failure : boost::exit_success;
}

View File

@@ -113,7 +113,7 @@ public:
template <class V2>
ptr_iterator(
const ptr_iterator<V2>& x
, typename boost::enable_if_convertible<V2, V>::type* = 0
, typename boost::enable_if_convertible<V2*, V*>::type* = 0
)
: super_t(x.base())
{}

View File

@@ -6,44 +6,52 @@
#include <boost/iterator/reverse_iterator.hpp>
#include <boost/iterator/new_iterator_tests.hpp>
#include <algorithm>
#include <deque>
using boost::dummyT;
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
namespace boost
{
namespace detail
{
template<> struct iterator_traits<dummyT*>
: ptr_iter_traits<dummyT> {};
template<> struct iterator_traits<dummyT const*>
: ptr_iter_traits<dummyT const> {};
}
}
#endif
// Test reverse iterator
int main()
{
#if 0
dummyT array[] = { dummyT(0), dummyT(1), dummyT(2),
dummyT(3), dummyT(4), dummyT(5) };
const int N = sizeof(array)/sizeof(dummyT);
// Test reverse_iterator_generator
{
dummyT reversed[N];
std::copy(array, array + N, reversed);
std::reverse(reversed, reversed + N);
typedef boost::reverse_iterator_generator<dummyT*
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) || defined(BOOST_NO_STD_ITERATOR_TRAITS)
, dummyT
#endif
>::type reverse_iterator;
typedef boost::reverse_iterator<dummyT*> reverse_iterator;
reverse_iterator i(reversed + N);
boost::random_access_iterator_test(i, N, array);
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
boost::random_access_iterator_test(boost::make_reverse_iterator(reversed + N), N, array);
#endif
typedef boost::reverse_iterator_generator<const dummyT*
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) || defined(BOOST_NO_STD_ITERATOR_TRAITS)
, dummyT, const dummyT&, const dummyT
#endif
>::type const_reverse_iterator;
typedef boost::reverse_iterator<const dummyT*> const_reverse_iterator;
const_reverse_iterator j(reversed + N);
boost::random_access_iterator_test(j, N, array);
const dummyT* const_reversed = reversed;
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
boost::random_access_iterator_test(boost::make_reverse_iterator(const_reversed + N), N, array);
#endif
boost::const_nonconst_iterator_test(i, ++j);
}
@@ -55,10 +63,10 @@ int main()
const std::deque<dummyT>::iterator reversed = reversed_container.begin();
typedef boost::reverse_iterator_generator<
std::deque<dummyT>::iterator>::type reverse_iterator;
typedef boost::reverse_iterator_generator<
std::deque<dummyT>::const_iterator, const dummyT>::type const_reverse_iterator;
typedef boost::reverse_iterator<
std::deque<dummyT>::iterator> reverse_iterator;
typedef boost::reverse_iterator<
std::deque<dummyT>::const_iterator> const_reverse_iterator;
// MSVC/STLport gives an INTERNAL COMPILER ERROR when any computation
// (e.g. "reversed + N") is used in the constructor below.
@@ -76,12 +84,14 @@ int main()
// Many compilers' builtin deque iterators don't interoperate well, though
// STLport fixes that problem.
#if defined(__SGI_STL_PORT) || !defined(__GNUC__) && !defined(__BORLANDC__) && (!defined(BOOST_MSVC) || BOOST_MSVC > 1200)
#if defined(__SGI_STL_PORT) \
|| !BOOST_WORKAROUND(__GNUC__, <= 2) \
&& !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) \
&& !BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, <= 1)
boost::const_nonconst_iterator_test(i, ++j);
#endif
}
#endif
}
return 0;
}