mirror of
https://github.com/boostorg/iterator.git
synced 2025-07-29 12:27:33 +02:00
Begun simplification
[SVN r20165]
This commit is contained in:
@ -39,40 +39,12 @@ namespace boost
|
||||
//
|
||||
// Access Categories
|
||||
//
|
||||
struct readable_iterator_tag
|
||||
enum iterator_access
|
||||
{
|
||||
typedef std::input_iterator_tag max_category;
|
||||
};
|
||||
|
||||
struct writable_iterator_tag
|
||||
{
|
||||
typedef std::output_iterator_tag max_category;
|
||||
};
|
||||
|
||||
struct swappable_iterator_tag
|
||||
{
|
||||
typedef detail::null_category_tag max_category;
|
||||
};
|
||||
|
||||
struct readable_writable_iterator_tag
|
||||
: virtual readable_iterator_tag
|
||||
, virtual writable_iterator_tag
|
||||
, virtual swappable_iterator_tag
|
||||
{
|
||||
typedef detail::input_output_iterator_tag max_category;
|
||||
};
|
||||
|
||||
struct readable_lvalue_iterator_tag
|
||||
: virtual readable_iterator_tag
|
||||
{
|
||||
typedef std::random_access_iterator_tag max_category;
|
||||
};
|
||||
|
||||
struct writable_lvalue_iterator_tag
|
||||
: virtual public readable_writable_iterator_tag
|
||||
, virtual public readable_lvalue_iterator_tag
|
||||
{
|
||||
typedef std::random_access_iterator_tag max_category;
|
||||
readable_iterator = 1
|
||||
, writable_iterator = 2
|
||||
, swappable_iterator = 4
|
||||
, lvalue_iterator = 8
|
||||
};
|
||||
|
||||
//
|
||||
@ -111,6 +83,11 @@ namespace boost
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <unsigned access>
|
||||
access_c : mpl::integral_c<iterator_access,access>
|
||||
{};
|
||||
|
||||
|
||||
//
|
||||
// Tag detection meta functions
|
||||
//
|
||||
@ -147,7 +124,7 @@ namespace boost
|
||||
// iterators which don't have an actual old-style category. We
|
||||
// need that so there is a valid base class for all new-style
|
||||
// iterators.
|
||||
# define BOOST_OLD_ITERATOR_CATEGORY(category) \
|
||||
# define BOOST_OLD_ITERATOR_CATEGORY(category) \
|
||||
template <> \
|
||||
struct is_tag <detail::null_category_tag, std::category> \
|
||||
: mpl::true_ {};
|
||||
|
@ -153,10 +153,8 @@ namespace boost
|
||||
typedef typename mpl::apply_if<
|
||||
mpl::or_<
|
||||
is_same<Category, use_default>
|
||||
, mpl::or_<
|
||||
is_access_tag<Category>
|
||||
, is_traversal_tag<Category>
|
||||
>
|
||||
, is_access_tag<Category>
|
||||
, is_traversal_tag<Category>
|
||||
>
|
||||
, BOOST_ITERATOR_CATEGORY<Base>
|
||||
, mpl::identity<Category>
|
||||
|
@ -105,7 +105,7 @@ namespace boost {
|
||||
|
||||
template <class Reference>
|
||||
struct apply
|
||||
: mpl::identity<readable_iterator_tag> {};
|
||||
: access_c<readable_iterator> {};
|
||||
|
||||
};
|
||||
|
||||
@ -116,7 +116,7 @@ namespace boost {
|
||||
|
||||
template <class Reference>
|
||||
struct apply
|
||||
: mpl::identity<writable_iterator_tag> {};
|
||||
: access_c<writable_iterator> {};
|
||||
};
|
||||
|
||||
template <>
|
||||
@ -128,8 +128,8 @@ namespace boost {
|
||||
struct apply
|
||||
: mpl::if_<
|
||||
python::detail::is_reference_to_const<Reference>
|
||||
, boost::readable_lvalue_iterator_tag
|
||||
, boost::writable_lvalue_iterator_tag
|
||||
, access_c<(readable_iterator|lvalue_iterator)>
|
||||
, access_c<(readable_iterator|writable_iterator|lvalue_iterator)>
|
||||
>
|
||||
{};
|
||||
};
|
||||
@ -151,30 +151,31 @@ namespace boost {
|
||||
template <class Category>
|
||||
struct old_tag_converter
|
||||
: std_to_new_tags<
|
||||
// Take the category down to its most-refined known
|
||||
// std::tag, in case of derivation/convertibility
|
||||
typename std_category<Category>::type
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
template <typename Category>
|
||||
struct iter_category_to_traversal
|
||||
: std_to_new_tags<
|
||||
typename std_category<Category>::type
|
||||
>
|
||||
{};
|
||||
|
||||
template <class OldTag>
|
||||
struct old_tag_to_traversal
|
||||
: old_tag_converter<OldTag>
|
||||
{};
|
||||
|
||||
|
||||
template <typename Category, typename Reference>
|
||||
struct iter_category_to_access
|
||||
struct old_tag_to_access
|
||||
: mpl::apply1<
|
||||
iter_category_to_traversal<Category>
|
||||
old_tag_converter<Category>
|
||||
, Reference
|
||||
>
|
||||
{};
|
||||
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
|
||||
// Deal with ETI
|
||||
template <> struct iter_category_to_access<int, int> {};
|
||||
template <> struct iter_category_to_traversal<int> {};
|
||||
template <> struct old_tag_to_access<int, int> {};
|
||||
template <> struct old_tag_converter<int> {};
|
||||
# endif
|
||||
|
||||
// A metafunction returning true iff T is boost::iterator_tag<R,U>
|
||||
@ -231,71 +232,49 @@ namespace boost {
|
||||
namespace detail {
|
||||
|
||||
template <class NewCategoryTag>
|
||||
struct get_traversal_category {
|
||||
typedef typename NewCategoryTag::traversal type;
|
||||
struct new_tag_to_traversal
|
||||
{
|
||||
typedef typename NewCategoryTag::traversal type;
|
||||
};
|
||||
|
||||
// Remove all writability from the given access tag. This
|
||||
// functionality is part of new_category_to_access in order to
|
||||
// support deduction of the proper default access category for
|
||||
// iterator_adaptor; when the reference type is a reference to
|
||||
// constant we must strip writability.
|
||||
template <class AccessTag>
|
||||
struct remove_access_writability
|
||||
: mpl::apply_if<
|
||||
is_tag<writable_lvalue_iterator_tag, AccessTag>
|
||||
, mpl::identity<readable_lvalue_iterator_tag>
|
||||
|
||||
, mpl::apply_if<
|
||||
is_tag<readable_writable_iterator_tag, AccessTag>
|
||||
, mpl::identity<readable_iterator_tag>
|
||||
|
||||
, mpl::if_<
|
||||
is_tag<writable_iterator_tag, AccessTag>
|
||||
// Is this OK? I think it may correct be for all
|
||||
// legitimate cases, because at this point the
|
||||
// iterator is not readable, so it could not have
|
||||
// been any more than writable + swappable.
|
||||
, swappable_iterator_tag
|
||||
, AccessTag
|
||||
>
|
||||
>
|
||||
>
|
||||
{};
|
||||
|
||||
template <class NewCategoryTag, class Reference>
|
||||
struct new_category_to_access
|
||||
struct new_tag_to_access
|
||||
{
|
||||
typedef typename NewCategoryTag::access_type type;
|
||||
}
|
||||
#if 0 // what was this all about?
|
||||
: mpl::apply_if<
|
||||
python::detail::is_reference_to_const<Reference>
|
||||
, remove_access_writability<typename NewCategoryTag::access>
|
||||
, mpl::identity<typename NewCategoryTag::access>
|
||||
>
|
||||
{};
|
||||
#endif
|
||||
|
||||
template <class CategoryTag, class Reference>
|
||||
struct access_category_tag
|
||||
: mpl::apply_if<
|
||||
is_new_iterator_tag<CategoryTag>
|
||||
, new_category_to_access<CategoryTag, Reference>
|
||||
, iter_category_to_access<CategoryTag, Reference>
|
||||
>
|
||||
struct tag_access_category
|
||||
: mpl::apply_if<
|
||||
is_new_iterator_tag<CategoryTag>
|
||||
, new_tag_to_access<CategoryTag>
|
||||
, old_tag_to_access<CategoryTag, Reference>
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
template <class CategoryTag>
|
||||
struct traversal_category_tag
|
||||
struct tag_traversal_category
|
||||
: mpl::apply_if<
|
||||
is_new_iterator_tag<CategoryTag>
|
||||
, get_traversal_category<CategoryTag>
|
||||
, iter_category_to_traversal<CategoryTag>
|
||||
, new_tag_to_traversal<CategoryTag>
|
||||
, old_tag_to_traversal<CategoryTag>
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
|
||||
// Deal with ETI
|
||||
template <> struct access_category_tag<int, int> { typedef void type; };
|
||||
template <> struct traversal_category_tag<int> { typedef void type; };
|
||||
template <> struct tag_access_category<int, int> { typedef void type; };
|
||||
template <> struct tag_traversal_category<int> { typedef void type; };
|
||||
# endif
|
||||
|
||||
// iterator_tag_base - a metafunction to compute the appropriate
|
||||
@ -330,14 +309,15 @@ namespace boost {
|
||||
|
||||
template <class Iterator>
|
||||
struct access_category
|
||||
: detail::access_category_tag<
|
||||
typename detail::iterator_traits<Iterator>::iterator_category
|
||||
, typename detail::iterator_traits<Iterator>::reference>
|
||||
: detail::tag_access_category<
|
||||
typename detail::iterator_traits<Iterator>::iterator_category
|
||||
, typename detail::iterator_traits<Iterator>::reference
|
||||
>
|
||||
{};
|
||||
|
||||
template <class Iterator>
|
||||
struct traversal_category
|
||||
: detail::traversal_category_tag<
|
||||
: detail::tag_traversal_category<
|
||||
typename detail::iterator_traits<Iterator>::iterator_category
|
||||
>
|
||||
{
|
||||
@ -349,7 +329,7 @@ namespace boost {
|
||||
// requires instantiating iterator_traits on the
|
||||
// placeholder. Instead we just specialize it as a metafunction
|
||||
// class.
|
||||
template <>
|
||||
template <>
|
||||
struct access_category<mpl::_1>
|
||||
{
|
||||
template <class T>
|
||||
@ -370,10 +350,11 @@ template <>
|
||||
|
||||
template <typename T>
|
||||
struct access_category<T*>
|
||||
: mpl::if_<
|
||||
: mpl::if_<
|
||||
is_const<T>
|
||||
, readable_lvalue_iterator_tag
|
||||
, writable_lvalue_iterator_tag>
|
||||
, detail::access_c<(readable_iterator|lvalue_iterator)>
|
||||
, detail::access_c<(readable_iterator|writable_iterator|lvalue_iterator)>
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
@ -385,15 +366,16 @@ template <>
|
||||
|
||||
# endif
|
||||
|
||||
template <class AccessTag, class TraversalTag>
|
||||
template <unsigned Access, class TraversalTag>
|
||||
struct iterator_tag
|
||||
: detail::iterator_tag_base<
|
||||
typename detail::max_known_access_tag<AccessTag>::type
|
||||
typename detail::max_known_access_tag<Access>::type
|
||||
, typename detail::max_known_traversal_tag<TraversalTag>::type
|
||||
>::type
|
||||
{
|
||||
typedef AccessTag access;
|
||||
typedef TraversalTag traversal;
|
||||
typedef detail::access_c<(Access & ~lvalue_iterator)> access_type;
|
||||
BOOST_STATIC_CONSTANT(iterator_access, access_type::value);
|
||||
typedef TraversalTag traversal;
|
||||
};
|
||||
|
||||
namespace detail
|
||||
|
@ -75,25 +75,6 @@ namespace boost
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Add const qualification for iterators which are not writable
|
||||
//
|
||||
template<class Value, class AccessCategory>
|
||||
struct const_qualified_ref :
|
||||
mpl::if_< is_tag< writable_iterator_tag, AccessCategory >,
|
||||
Value&,
|
||||
Value const& >
|
||||
{};
|
||||
|
||||
// The apparent duplication here works around a Borland problem
|
||||
template<class Value, class AccessCategory>
|
||||
struct const_qualified_ptr :
|
||||
mpl::if_< is_tag< writable_iterator_tag, AccessCategory >,
|
||||
Value*,
|
||||
Value const* >
|
||||
{};
|
||||
|
||||
//
|
||||
// Generates the associated types for an iterator_facade with the
|
||||
// given parameters. Additionally generates a 'base' type for
|
||||
@ -104,7 +85,7 @@ namespace boost
|
||||
class Value
|
||||
, class AccessCategory
|
||||
, class TraversalCategory
|
||||
, class Reference
|
||||
, class Reference
|
||||
, class Difference
|
||||
>
|
||||
struct iterator_facade_types
|
||||
@ -117,17 +98,6 @@ namespace boost
|
||||
|
||||
typedef typename const_qualified_ptr<Value, AccessCategory>::type pointer;
|
||||
|
||||
// The use_default support is needed for iterator_adaptor.
|
||||
// For practical reasons iterator_adaptor needs to specify
|
||||
// a fixed number of template arguments of iterator_facade.
|
||||
// So use_default is its way to say: "What I really mean
|
||||
// is your default parameter".
|
||||
typedef typename mpl::if_<
|
||||
is_same<Reference, use_default>
|
||||
, typename const_qualified_ref<Value, AccessCategory>::type
|
||||
, Reference
|
||||
>::type reference;
|
||||
|
||||
# if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
|
||||
&& (BOOST_WORKAROUND(_STLPORT_VERSION, BOOST_TESTED_AT(0x452)) \
|
||||
|| BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, BOOST_TESTED_AT(310))) \
|
||||
@ -372,7 +342,7 @@ namespace boost
|
||||
, class Value
|
||||
, class AccessCategory
|
||||
, class TraversalCategory
|
||||
, class Reference = BOOST_DEDUCED_TYPENAME detail::const_qualified_ref<Value, AccessCategory>::type
|
||||
, class Reference = Value&
|
||||
, class Difference = std::ptrdiff_t
|
||||
>
|
||||
class iterator_facade
|
||||
@ -384,10 +354,6 @@ namespace boost
|
||||
# endif
|
||||
{
|
||||
private:
|
||||
typedef typename
|
||||
detail::iterator_facade_types<Value, AccessCategory, TraversalCategory, Reference, Difference>
|
||||
types;
|
||||
|
||||
//
|
||||
// Curiously Recursive Template interface.
|
||||
//
|
||||
@ -405,9 +371,9 @@ namespace boost
|
||||
|
||||
public:
|
||||
|
||||
typedef typename types::value_type value_type;
|
||||
typedef typename types::reference reference;
|
||||
typedef typename types::difference_type difference_type;
|
||||
typedef typename remove_cv<Value> value_type;
|
||||
typedef typename Reference reference;
|
||||
typedef typename Difference difference_type;
|
||||
typedef typename types::pointer pointer;
|
||||
typedef typename types::iterator_category iterator_category;
|
||||
|
||||
|
Reference in New Issue
Block a user