mirror of
https://github.com/boostorg/iterator.git
synced 2025-05-09 23:23:54 +00:00
Moved minimum_category to the public namespace. Added tests.
This commit is contained in:
parent
8fe632d6b1
commit
f158dba6ad
@ -11,7 +11,7 @@ namespace boost {
|
|||||||
// This import below (as well as the whole header) is for backward compatibility
|
// 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.
|
// with boost/token_iterator.hpp. It should be removed as soon as that header is fixed.
|
||||||
namespace detail {
|
namespace detail {
|
||||||
using iterators::detail::minimum_category;
|
using iterators::minimum_category;
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
@ -1,27 +1,20 @@
|
|||||||
// Copyright David Abrahams 2003. Use, modification and distribution is
|
// Copyright David Abrahams 2003. Use, modification and distribution is
|
||||||
// subject to the Boost Software License, Version 1.0. (See accompanying
|
// 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)
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
#ifndef MINIMUM_CATEGORY_DWA20031119_HPP
|
#ifndef BOOST_ITERATOR_MINIMUM_CATEGORY_HPP_INCLUDED_
|
||||||
# define MINIMUM_CATEGORY_DWA20031119_HPP
|
# define BOOST_ITERATOR_MINIMUM_CATEGORY_HPP_INCLUDED_
|
||||||
|
|
||||||
|
# include <boost/static_assert.hpp>
|
||||||
# include <boost/type_traits/is_convertible.hpp>
|
# include <boost/type_traits/is_convertible.hpp>
|
||||||
# include <boost/type_traits/is_same.hpp>
|
# include <boost/type_traits/is_same.hpp>
|
||||||
|
|
||||||
|
# include <boost/mpl/placeholders.hpp>
|
||||||
# include <boost/mpl/aux_/lambda_support.hpp>
|
# include <boost/mpl/aux_/lambda_support.hpp>
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace iterators {
|
namespace iterators {
|
||||||
namespace detail {
|
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>
|
template <bool GreaterEqual, bool LessEqual>
|
||||||
struct minimum_category_impl;
|
struct minimum_category_impl;
|
||||||
|
|
||||||
@ -60,15 +53,21 @@ template <>
|
|||||||
struct minimum_category_impl<false,false>
|
struct minimum_category_impl<false,false>
|
||||||
{
|
{
|
||||||
template <class T1, class T2> struct apply
|
template <class T1, class T2> struct apply
|
||||||
: error_not_related_by_convertibility<T1,T2>
|
: 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>
|
template <class T1 = mpl::_1, class T2 = mpl::_2>
|
||||||
struct minimum_category
|
struct minimum_category
|
||||||
{
|
{
|
||||||
typedef minimum_category_impl<
|
typedef boost::iterators::detail::minimum_category_impl<
|
||||||
::boost::is_convertible<T1,T2>::value
|
::boost::is_convertible<T1,T2>::value
|
||||||
, ::boost::is_convertible<T2,T1>::value
|
, ::boost::is_convertible<T2,T1>::value
|
||||||
> outer;
|
> outer;
|
||||||
@ -89,15 +88,8 @@ struct minimum_category<mpl::_1,mpl::_2>
|
|||||||
BOOST_MPL_AUX_LAMBDA_SUPPORT_SPEC(2,minimum_category,(mpl::_1,mpl::_2))
|
BOOST_MPL_AUX_LAMBDA_SUPPORT_SPEC(2,minimum_category,(mpl::_1,mpl::_2))
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
} // namespace iterators
|
} // 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;
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
#endif // MINIMUM_CATEGORY_DWA20031119_HPP
|
#endif // BOOST_ITERATOR_MINIMUM_CATEGORY_HPP_INCLUDED_
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
#include <boost/iterator/iterator_categories.hpp>
|
#include <boost/iterator/iterator_categories.hpp>
|
||||||
#include <boost/detail/iterator.hpp>
|
#include <boost/detail/iterator.hpp>
|
||||||
|
|
||||||
#include <boost/iterator/detail/minimum_category.hpp>
|
#include <boost/iterator/minimum_category.hpp>
|
||||||
|
|
||||||
#include <boost/tuple/tuple.hpp>
|
#include <boost/tuple/tuple.hpp>
|
||||||
|
|
||||||
|
@ -46,4 +46,7 @@ test-suite iterator
|
|||||||
[ run function_input_iterator_test.cpp ]
|
[ run function_input_iterator_test.cpp ]
|
||||||
|
|
||||||
[ run generator_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 "static_assert_same.hpp"
|
||||||
|
|
||||||
#include <boost/iterator/detail/minimum_category.hpp>
|
#include <boost/iterator/minimum_category.hpp>
|
||||||
|
|
||||||
struct X { int a; };
|
struct X { int a; };
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ void operator_arrow_test()
|
|||||||
template <class T, class U, class Min>
|
template <class T, class U, class Min>
|
||||||
struct static_assert_min_cat
|
struct static_assert_min_cat
|
||||||
: static_assert_same<
|
: static_assert_same<
|
||||||
typename boost::iterators::detail::minimum_category<T,U>::type, Min
|
typename boost::iterators::minimum_category<T,U>::type, Min
|
||||||
>
|
>
|
||||||
{};
|
{};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user