mirror of
https://github.com/boostorg/iterator.git
synced 2025-07-30 12:57:23 +02:00
Merge pull request #6 from Lastique/publish-details
Publish some of the implementation details Tested with clang-5.1 on darwin.
This commit is contained in:
@ -4,98 +4,14 @@
|
||||
#ifndef MINIMUM_CATEGORY_DWA20031119_HPP
|
||||
# define MINIMUM_CATEGORY_DWA20031119_HPP
|
||||
|
||||
# include <boost/type_traits/is_convertible.hpp>
|
||||
# include <boost/type_traits/is_same.hpp>
|
||||
|
||||
# include <boost/mpl/aux_/lambda_support.hpp>
|
||||
# include <boost/iterator/minimum_category.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace iterators {
|
||||
|
||||
// This import below (as well as the whole header) is for backward compatibility
|
||||
// with boost/token_iterator.hpp. It should be removed as soon as that header is fixed.
|
||||
namespace detail {
|
||||
//
|
||||
// Returns the minimum category type or error_type
|
||||
// if T1 and T2 are unrelated.
|
||||
//
|
||||
// For compilers not supporting is_convertible this only
|
||||
// works with the new boost return and traversal category
|
||||
// types. The exact boost _types_ are required. No derived types
|
||||
// will work.
|
||||
//
|
||||
//
|
||||
template <bool GreaterEqual, bool LessEqual>
|
||||
struct minimum_category_impl;
|
||||
|
||||
template <class T1, class T2>
|
||||
struct error_not_related_by_convertibility;
|
||||
|
||||
template <>
|
||||
struct minimum_category_impl<true,false>
|
||||
{
|
||||
template <class T1, class T2> struct apply
|
||||
{
|
||||
typedef T2 type;
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct minimum_category_impl<false,true>
|
||||
{
|
||||
template <class T1, class T2> struct apply
|
||||
{
|
||||
typedef T1 type;
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct minimum_category_impl<true,true>
|
||||
{
|
||||
template <class T1, class T2> struct apply
|
||||
{
|
||||
BOOST_STATIC_ASSERT((is_same<T1,T2>::value));
|
||||
typedef T1 type;
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct minimum_category_impl<false,false>
|
||||
{
|
||||
template <class T1, class T2> struct apply
|
||||
: error_not_related_by_convertibility<T1,T2>
|
||||
{
|
||||
};
|
||||
};
|
||||
|
||||
template <class T1 = mpl::_1, class T2 = mpl::_2>
|
||||
struct minimum_category
|
||||
{
|
||||
typedef minimum_category_impl<
|
||||
::boost::is_convertible<T1,T2>::value
|
||||
, ::boost::is_convertible<T2,T1>::value
|
||||
> outer;
|
||||
|
||||
typedef typename outer::template apply<T1,T2> inner;
|
||||
typedef typename inner::type type;
|
||||
|
||||
BOOST_MPL_AUX_LAMBDA_SUPPORT(2,minimum_category,(T1,T2))
|
||||
};
|
||||
|
||||
template <>
|
||||
struct minimum_category<mpl::_1,mpl::_2>
|
||||
{
|
||||
template <class T1, class T2>
|
||||
struct apply : minimum_category<T1,T2>
|
||||
{};
|
||||
|
||||
BOOST_MPL_AUX_LAMBDA_SUPPORT_SPEC(2,minimum_category,(mpl::_1,mpl::_2))
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace iterators
|
||||
|
||||
// This import below is for backward compatibility with boost/token_iterator.hpp.
|
||||
// It should be removed as soon as that header is fixed.
|
||||
namespace detail {
|
||||
using iterators::detail::minimum_category;
|
||||
using iterators::minimum_category;
|
||||
} // namespace detail
|
||||
|
||||
} // namespace boost
|
||||
|
@ -98,35 +98,8 @@ namespace detail
|
||||
>
|
||||
{};
|
||||
|
||||
template <class Traversal>
|
||||
struct pure_traversal_tag
|
||||
: mpl::eval_if<
|
||||
is_convertible<Traversal,random_access_traversal_tag>
|
||||
, mpl::identity<random_access_traversal_tag>
|
||||
, mpl::eval_if<
|
||||
is_convertible<Traversal,bidirectional_traversal_tag>
|
||||
, mpl::identity<bidirectional_traversal_tag>
|
||||
, mpl::eval_if<
|
||||
is_convertible<Traversal,forward_traversal_tag>
|
||||
, mpl::identity<forward_traversal_tag>
|
||||
, mpl::eval_if<
|
||||
is_convertible<Traversal,single_pass_traversal_tag>
|
||||
, mpl::identity<single_pass_traversal_tag>
|
||||
, mpl::eval_if<
|
||||
is_convertible<Traversal,incrementable_traversal_tag>
|
||||
, mpl::identity<incrementable_traversal_tag>
|
||||
, void
|
||||
>
|
||||
>
|
||||
>
|
||||
>
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
|
||||
//
|
||||
// Convert an iterator category into a traversal tag
|
||||
//
|
||||
@ -166,6 +139,64 @@ struct iterator_traversal<mpl::_>
|
||||
{};
|
||||
# endif
|
||||
|
||||
//
|
||||
// Convert an iterator traversal to one of the traversal tags.
|
||||
//
|
||||
template <class Traversal>
|
||||
struct pure_traversal_tag
|
||||
: mpl::eval_if<
|
||||
is_convertible<Traversal,random_access_traversal_tag>
|
||||
, mpl::identity<random_access_traversal_tag>
|
||||
, mpl::eval_if<
|
||||
is_convertible<Traversal,bidirectional_traversal_tag>
|
||||
, mpl::identity<bidirectional_traversal_tag>
|
||||
, mpl::eval_if<
|
||||
is_convertible<Traversal,forward_traversal_tag>
|
||||
, mpl::identity<forward_traversal_tag>
|
||||
, mpl::eval_if<
|
||||
is_convertible<Traversal,single_pass_traversal_tag>
|
||||
, mpl::identity<single_pass_traversal_tag>
|
||||
, mpl::eval_if<
|
||||
is_convertible<Traversal,incrementable_traversal_tag>
|
||||
, mpl::identity<incrementable_traversal_tag>
|
||||
, void
|
||||
>
|
||||
>
|
||||
>
|
||||
>
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
// This import is needed for backward compatibility with Boost.Range:
|
||||
// boost/range/detail/demote_iterator_traversal_tag.hpp
|
||||
// It should be removed when that header is fixed.
|
||||
namespace detail {
|
||||
using iterators::pure_traversal_tag;
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// Trait to retrieve one of the iterator traversal tags from the iterator category or traversal.
|
||||
//
|
||||
template <class Iterator = mpl::_1>
|
||||
struct pure_iterator_traversal
|
||||
: pure_traversal_tag<typename iterator_traversal<Iterator>::type>
|
||||
{};
|
||||
|
||||
# ifdef BOOST_MPL_CFG_NO_FULL_LAMBDA_SUPPORT
|
||||
template <>
|
||||
struct pure_iterator_traversal<mpl::_1>
|
||||
{
|
||||
template <class T>
|
||||
struct apply : pure_iterator_traversal<T>
|
||||
{};
|
||||
};
|
||||
template <>
|
||||
struct pure_iterator_traversal<mpl::_>
|
||||
: pure_iterator_traversal<mpl::_1>
|
||||
{};
|
||||
# endif
|
||||
|
||||
} // namespace iterators
|
||||
|
||||
using iterators::no_traversal_tag;
|
||||
@ -177,6 +208,13 @@ using iterators::random_access_traversal_tag;
|
||||
using iterators::iterator_category_to_traversal;
|
||||
using iterators::iterator_traversal;
|
||||
|
||||
// This import is needed for backward compatibility with Boost.Range:
|
||||
// boost/range/detail/demote_iterator_traversal_tag.hpp
|
||||
// It should be removed when that header is fixed.
|
||||
namespace detail {
|
||||
using iterators::pure_traversal_tag;
|
||||
} // namespace detail
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/iterator/detail/config_undef.hpp>
|
||||
|
@ -248,19 +248,10 @@ namespace boost_concepts
|
||||
BOOST_concept(InteroperableIterator,(Iterator)(ConstIterator))
|
||||
{
|
||||
private:
|
||||
typedef typename boost::iterators::detail::pure_traversal_tag<
|
||||
typename boost::iterator_traversal<
|
||||
Iterator
|
||||
>::type
|
||||
>::type traversal_category;
|
||||
typedef typename boost::iterators::pure_iterator_traversal<Iterator>::type traversal_category;
|
||||
typedef typename boost::iterators::pure_iterator_traversal<ConstIterator>::type const_traversal_category;
|
||||
|
||||
typedef typename boost::iterators::detail::pure_traversal_tag<
|
||||
typename boost::iterator_traversal<
|
||||
ConstIterator
|
||||
>::type
|
||||
>::type const_traversal_category;
|
||||
|
||||
public:
|
||||
public:
|
||||
BOOST_CONCEPT_ASSERT((SinglePassIterator<Iterator>));
|
||||
BOOST_CONCEPT_ASSERT((SinglePassIterator<ConstIterator>));
|
||||
|
||||
|
95
include/boost/iterator/minimum_category.hpp
Normal file
95
include/boost/iterator/minimum_category.hpp
Normal file
@ -0,0 +1,95 @@
|
||||
// Copyright David Abrahams 2003. Use, modification and distribution is
|
||||
// subject to the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
#ifndef BOOST_ITERATOR_MINIMUM_CATEGORY_HPP_INCLUDED_
|
||||
# define BOOST_ITERATOR_MINIMUM_CATEGORY_HPP_INCLUDED_
|
||||
|
||||
# include <boost/static_assert.hpp>
|
||||
# include <boost/type_traits/is_convertible.hpp>
|
||||
# include <boost/type_traits/is_same.hpp>
|
||||
|
||||
# include <boost/mpl/placeholders.hpp>
|
||||
# include <boost/mpl/aux_/lambda_support.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace iterators {
|
||||
namespace detail {
|
||||
|
||||
template <bool GreaterEqual, bool LessEqual>
|
||||
struct minimum_category_impl;
|
||||
|
||||
template <class T1, class T2>
|
||||
struct error_not_related_by_convertibility;
|
||||
|
||||
template <>
|
||||
struct minimum_category_impl<true,false>
|
||||
{
|
||||
template <class T1, class T2> struct apply
|
||||
{
|
||||
typedef T2 type;
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct minimum_category_impl<false,true>
|
||||
{
|
||||
template <class T1, class T2> struct apply
|
||||
{
|
||||
typedef T1 type;
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct minimum_category_impl<true,true>
|
||||
{
|
||||
template <class T1, class T2> struct apply
|
||||
{
|
||||
BOOST_STATIC_ASSERT((is_same<T1,T2>::value));
|
||||
typedef T1 type;
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct minimum_category_impl<false,false>
|
||||
{
|
||||
template <class T1, class T2> struct apply
|
||||
: error_not_related_by_convertibility<T1,T2>
|
||||
{
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// Returns the minimum category type or fails to compile
|
||||
// if T1 and T2 are unrelated.
|
||||
//
|
||||
template <class T1 = mpl::_1, class T2 = mpl::_2>
|
||||
struct minimum_category
|
||||
{
|
||||
typedef boost::iterators::detail::minimum_category_impl<
|
||||
::boost::is_convertible<T1,T2>::value
|
||||
, ::boost::is_convertible<T2,T1>::value
|
||||
> outer;
|
||||
|
||||
typedef typename outer::template apply<T1,T2> inner;
|
||||
typedef typename inner::type type;
|
||||
|
||||
BOOST_MPL_AUX_LAMBDA_SUPPORT(2,minimum_category,(T1,T2))
|
||||
};
|
||||
|
||||
template <>
|
||||
struct minimum_category<mpl::_1,mpl::_2>
|
||||
{
|
||||
template <class T1, class T2>
|
||||
struct apply : minimum_category<T1,T2>
|
||||
{};
|
||||
|
||||
BOOST_MPL_AUX_LAMBDA_SUPPORT_SPEC(2,minimum_category,(mpl::_1,mpl::_2))
|
||||
};
|
||||
|
||||
} // namespace iterators
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_ITERATOR_MINIMUM_CATEGORY_HPP_INCLUDED_
|
@ -14,7 +14,7 @@
|
||||
#include <boost/iterator/iterator_categories.hpp>
|
||||
#include <boost/detail/iterator.hpp>
|
||||
|
||||
#include <boost/iterator/detail/minimum_category.hpp>
|
||||
#include <boost/iterator/minimum_category.hpp>
|
||||
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
|
||||
|
@ -3,28 +3,28 @@
|
||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
test-suite iterator
|
||||
:
|
||||
:
|
||||
# These first two tests will run last, and are expected to fail
|
||||
# for many less-capable compilers.
|
||||
|
||||
|
||||
[ compile-fail interoperable_fail.cpp ]
|
||||
# test uses expected success, so that we catch unrelated
|
||||
# compilation problems.
|
||||
[ run is_convertible_fail.cpp ]
|
||||
[ run is_convertible_fail.cpp ]
|
||||
|
||||
[ run zip_iterator_test.cpp
|
||||
: : :
|
||||
|
||||
: : :
|
||||
|
||||
# stlport's debug mode generates long symbols which overwhelm
|
||||
# vc6
|
||||
#<msvc-stlport><*><runtime-build>release
|
||||
#<msvc-stlport><*><runtime-build>release
|
||||
]
|
||||
|
||||
|
||||
# These tests should work for just about everything.
|
||||
[ compile is_lvalue_iterator.cpp ]
|
||||
[ compile is_readable_iterator.cpp ]
|
||||
[ compile pointee.cpp ]
|
||||
|
||||
|
||||
[ run unit_tests.cpp ]
|
||||
[ run concept_tests.cpp ]
|
||||
[ run iterator_adaptor_cc.cpp ]
|
||||
@ -41,9 +41,12 @@ test-suite iterator
|
||||
[ run counting_iterator_test.cpp ]
|
||||
[ run interoperable.cpp ]
|
||||
[ run iterator_traits_test.cpp ]
|
||||
[ run permutation_iterator_test.cpp : : : # <stlport-iostream>on
|
||||
[ run permutation_iterator_test.cpp : : : # <stlport-iostream>on
|
||||
]
|
||||
[ run function_input_iterator_test.cpp ]
|
||||
|
||||
|
||||
[ run generator_iterator_test.cpp ]
|
||||
|
||||
[ run minimum_category.cpp ]
|
||||
[ compile-fail minimum_category_compile_fail.cpp ]
|
||||
;
|
||||
|
22
test/minimum_category.cpp
Normal file
22
test/minimum_category.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright Andrey Semashev 2014.
|
||||
//
|
||||
// Use, modification and distribution is subject to
|
||||
// the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/iterator/minimum_category.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <iterator>
|
||||
|
||||
using boost::is_same;
|
||||
using boost::iterators::minimum_category;
|
||||
|
||||
int main(int, char*[])
|
||||
{
|
||||
BOOST_TEST_TRAIT_TRUE((is_same<minimum_category<std::forward_iterator_tag, std::random_access_iterator_tag>::type, std::forward_iterator_tag>));
|
||||
BOOST_TEST_TRAIT_TRUE((is_same<minimum_category<std::random_access_iterator_tag, std::forward_iterator_tag>::type, std::forward_iterator_tag>));
|
||||
BOOST_TEST_TRAIT_TRUE((is_same<minimum_category<std::random_access_iterator_tag, std::random_access_iterator_tag>::type, std::random_access_iterator_tag>));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
19
test/minimum_category_compile_fail.cpp
Normal file
19
test/minimum_category_compile_fail.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright Andrey Semashev 2014.
|
||||
//
|
||||
// Use, modification and distribution is subject to
|
||||
// the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/iterator/minimum_category.hpp>
|
||||
|
||||
using boost::iterators::minimum_category;
|
||||
|
||||
struct A {};
|
||||
struct B {};
|
||||
|
||||
int main(int, char*[])
|
||||
{
|
||||
minimum_category<A, B>::type cat;
|
||||
|
||||
return 0;
|
||||
}
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "static_assert_same.hpp"
|
||||
|
||||
#include <boost/iterator/detail/minimum_category.hpp>
|
||||
#include <boost/iterator/minimum_category.hpp>
|
||||
|
||||
struct X { int a; };
|
||||
|
||||
@ -29,7 +29,7 @@ void operator_arrow_test()
|
||||
template <class T, class U, class Min>
|
||||
struct static_assert_min_cat
|
||||
: static_assert_same<
|
||||
typename boost::iterators::detail::minimum_category<T,U>::type, Min
|
||||
typename boost::iterators::minimum_category<T,U>::type, Min
|
||||
>
|
||||
{};
|
||||
|
||||
|
@ -55,13 +55,6 @@
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <stddef.h>
|
||||
|
||||
template <class It>
|
||||
struct pure_traversal
|
||||
: boost::iterators::detail::pure_traversal_tag<
|
||||
typename boost::iterator_traversal<It>::type
|
||||
>
|
||||
{};
|
||||
|
||||
|
||||
/// Tests for https://svn.boost.org/trac/boost/ticket/1517
|
||||
int to_value(int const &v)
|
||||
|
Reference in New Issue
Block a user