merged from trunk

[SVN r21801]
This commit is contained in:
Dave Abrahams
2004-01-18 16:21:14 +00:00
parent 5d71ddeec4
commit c90b123e7a
2 changed files with 90 additions and 39 deletions

View File

@ -19,6 +19,8 @@
#include <boost/type_traits/remove_const.hpp>
#include <boost/type_traits/remove_cv.hpp>
#include <boost/concept_archetype.hpp>
#include <boost/mpl/aux_/msvc_eti_base.hpp>
#include <boost/mpl/bitand.hpp>
#include <boost/mpl/int.hpp>
@ -80,26 +82,26 @@ namespace detail
template <class T>
struct assign_proxy
{
assign_proxy& operator=(T);
assign_proxy& operator=(T) { return *this; }
};
template <class T>
struct read_proxy
{
operator T();
operator T() { return static_object<T>::get(); }
};
template <class T>
struct read_write_proxy
: assign_proxy<T>
, read_proxy<T>
: read_proxy<T> // Use to inherit from assign_proxy, but that doesn't work. -JGS
{
read_write_proxy& operator=(T) { return *this; }
};
template <class T>
struct arrow_proxy
{
T const* operator->() const;
T const* operator->() const { return 0; }
};
struct no_operator_brackets {};
@ -107,13 +109,13 @@ namespace detail
template <class ValueType>
struct readable_operator_brackets
{
read_proxy<ValueType> operator[](std::ptrdiff_t n) const;
read_proxy<ValueType> operator[](std::ptrdiff_t n) const { return read_proxy<ValueType>(); }
};
template <class ValueType>
struct writable_operator_brackets
{
read_write_proxy<ValueType> operator[](std::ptrdiff_t n) const;
read_write_proxy<ValueType> operator[](std::ptrdiff_t n) const { return read_write_proxy<ValueType>(); }
};
template <class Value, class AccessCategory, class TraversalCategory>
@ -147,12 +149,26 @@ namespace detail
template <class Derived,class Value> struct archetype;
};
// Constructor argument for those iterators that
// are not default constructible
struct ctor_arg {};
template <class Derived, class Value, class TraversalCategory>
struct traversal_archetype_
: mpl::aux::msvc_eti_base<
typename traversal_archetype_impl<TraversalCategory>::template archetype<Derived,Value>
>::type
{};
{
typedef typename
traversal_archetype_impl<TraversalCategory>::template archetype<Derived,Value>
base;
traversal_archetype_() {}
traversal_archetype_(ctor_arg arg)
: base(arg)
{}
};
template <>
struct traversal_archetype_impl<incrementable_traversal_tag>
@ -160,10 +176,13 @@ namespace detail
template<class Derived, class Value>
struct archetype
{
typedef void difference_type;
explicit archetype(ctor_arg) {}
Derived& operator++();
Derived operator++(int) const;
struct bogus { }; // This use to be void, but that causes trouble for iterator_facade. Need more research. -JGS
typedef bogus difference_type;
Derived& operator++() { return (Derived&)static_object<Derived>::get(); }
Derived operator++(int) const { return (Derived&)static_object<Derived>::get(); }
};
};
@ -175,18 +194,21 @@ namespace detail
: public equality_comparable< traversal_archetype_<Derived, Value, single_pass_traversal_tag> >,
public traversal_archetype_<Derived, Value, incrementable_traversal_tag>
{
explicit archetype(ctor_arg arg)
: traversal_archetype_<Derived, Value, incrementable_traversal_tag>(arg)
{}
};
};
template <class Derived, class Value>
bool operator==(traversal_archetype_<Derived, Value, single_pass_traversal_tag> const&,
traversal_archetype_<Derived, Value, single_pass_traversal_tag> const&);
traversal_archetype_<Derived, Value, single_pass_traversal_tag> const&) { return true; }
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
// doesn't seem to pick up != from equality_comparable
template <class Derived, class Value>
bool operator!=(traversal_archetype_<Derived, Value, single_pass_traversal_tag> const&,
traversal_archetype_<Derived, Value, single_pass_traversal_tag> const&);
traversal_archetype_<Derived, Value, single_pass_traversal_tag> const&) { return true; }
#endif
template <>
struct traversal_archetype_impl<forward_traversal_tag>
@ -195,6 +217,9 @@ namespace detail
struct archetype
: public traversal_archetype_<Derived, Value, single_pass_traversal_tag>
{
archetype()
: traversal_archetype_<Derived, Value, single_pass_traversal_tag>(ctor_arg())
{}
typedef std::ptrdiff_t difference_type;
};
};
@ -206,8 +231,8 @@ namespace detail
struct archetype
: public traversal_archetype_<Derived, Value, forward_traversal_tag>
{
Derived& operator--();
Derived operator--(int) const;
Derived& operator--() { return static_object<Derived>::get(); }
Derived operator--(int) const { return static_object<Derived>::get(); }
};
};
@ -219,30 +244,34 @@ namespace detail
: public partially_ordered<traversal_archetype_<Derived, Value, random_access_traversal_tag> >,
public traversal_archetype_<Derived, Value, bidirectional_traversal_tag>
{
Derived& operator+=(std::ptrdiff_t);
Derived& operator-=(std::ptrdiff_t);
Derived& operator+=(std::ptrdiff_t) { return static_object<Derived>::get(); }
Derived& operator-=(std::ptrdiff_t) { return static_object<Derived>::get(); }
};
};
template <class Derived, class Value>
Derived& operator+(traversal_archetype_<Derived, Value, random_access_traversal_tag> const&,
std::ptrdiff_t);
std::ptrdiff_t) { return static_object<Derived>::get(); }
template <class Derived, class Value>
Derived& operator+(std::ptrdiff_t,
traversal_archetype_<Derived, Value, random_access_traversal_tag> const&);
traversal_archetype_<Derived, Value, random_access_traversal_tag> const&)
{ return static_object<Derived>::get(); }
template <class Derived, class Value>
Derived& operator-(traversal_archetype_<Derived, Value, random_access_traversal_tag> const&,
std::ptrdiff_t);
std::ptrdiff_t)
{ return static_object<Derived>::get(); }
template <class Derived, class Value>
std::ptrdiff_t operator-(traversal_archetype_<Derived, Value, random_access_traversal_tag> const&,
traversal_archetype_<Derived, Value, random_access_traversal_tag> const&);
traversal_archetype_<Derived, Value, random_access_traversal_tag> const&)
{ return 0; }
template <class Derived, class Value>
bool operator<(traversal_archetype_<Derived, Value, random_access_traversal_tag> const&,
traversal_archetype_<Derived, Value, random_access_traversal_tag> const&);
traversal_archetype_<Derived, Value, random_access_traversal_tag> const&)
{ return true; }
struct bogus_type;
@ -286,9 +315,9 @@ struct iterator_access_archetype_impl<
typedef Value reference;
typedef Value* pointer;
value_type operator*() const;
value_type operator*() const { return static_object<value_type>::get(); }
detail::arrow_proxy<Value> operator->() const;
detail::arrow_proxy<Value> operator->() const { return detail::arrow_proxy<Value>(); }
};
};
@ -307,7 +336,7 @@ struct iterator_access_archetype_impl<
typedef void reference;
typedef void pointer;
detail::assign_proxy<Value> operator*() const;
detail::assign_proxy<Value> operator*() const { return detail::assign_proxy<Value>(); }
};
};
@ -324,7 +353,7 @@ struct iterator_access_archetype_impl<
{
typedef detail::read_write_proxy<Value> reference;
detail::read_write_proxy<Value> operator*() const;
detail::read_write_proxy<Value> operator*() const { return detail::read_write_proxy<Value>(); }
};
};
@ -339,8 +368,8 @@ struct iterator_access_archetype_impl<iterator_archetypes::readable_lvalue_itera
{
typedef Value& reference;
Value& operator*() const;
Value* operator->() const;
Value& operator*() const { return static_object<Value>::get(); }
Value* operator->() const { return 0; }
};
};
@ -443,13 +472,27 @@ struct iterator_archetype
typedef typename base::iterator_category iterator_category;
# endif
iterator_archetype();
iterator_archetype(iterator_archetype const&);
iterator_archetype() { }
iterator_archetype(iterator_archetype const& x)
: detail::iterator_archetype_base<
Value
, AccessCategory
, TraversalCategory
>(x)
{}
iterator_archetype& operator=(iterator_archetype const&);
iterator_archetype& operator=(iterator_archetype const&)
{ return *this; }
# if 0
// Optional conversion from mutable
// iterator_archetype(iterator_archetype<typename detail::convertible_type<Value>::type, AccessCategory, TraversalCategory> const&);
iterator_archetype(
iterator_archetype<
typename detail::convertible_type<Value>::type
, AccessCategory
, TraversalCategory> const&
);
# endif
};
} // namespace boost

View File

@ -31,6 +31,10 @@
#include <boost/mpl/always.hpp>
#include <boost/mpl/apply.hpp>
#if BOOST_WORKAROUND(BOOST_MSVC, == 1200)
# include <boost/mpl/if.hpp>
#endif
#include <boost/iterator/detail/config_def.hpp> // this goes last
namespace boost
@ -223,16 +227,20 @@ namespace boost
{
template <class I1, class I2>
struct apply
: mpl::apply_if<
is_convertible<I2,I1>
:
# if BOOST_WORKAROUND(BOOST_MSVC, == 1200)
, typename I1::difference_type
, typename I2::difference_type
mpl::if_<
is_convertible<I2,I1>
, typename I1::difference_type
, typename I2::difference_type
>
# else
, iterator_difference<I1>
, iterator_difference<I2>
mpl::apply_if<
is_convertible<I2,I1>
, iterator_difference<I1>
, iterator_difference<I2>
>
# endif
>
{};
};