change to new/old category recognition code

[SVN r613]
This commit is contained in:
Jeremy Siek
2002-10-24 18:56:16 +00:00
parent 560c48fe7a
commit 5fd440c1d0
3 changed files with 84 additions and 24 deletions

View File

@@ -12,7 +12,8 @@
#include <boost/type_traits/cv_traits.hpp>
#include <boost/pending/ct_if.hpp>
#include <boost/detail/iterator.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/apply_if.hpp>
#include <boost/type_traits/ice.hpp>
#include <iterator>
namespace boost {
@@ -119,6 +120,7 @@ namespace boost {
>::type type;
};
#if 0
struct return_category_from_old_traits {
template <typename Iterator> class bind {
typedef boost::detail::iterator_traits<Iterator> OldTraits;
@@ -157,9 +159,25 @@ namespace boost {
public:
typedef typename Choice:: template bind<Iterator>::type type;
};
#else
template <class T>
type_traits::yes_type is_new_iter_cat(T*, typename T::traversal* = 0) { }
type_traits::no_type is_new_iter_cat(...) { }
template <class Tag>
struct is_new_iterator_tag
{
static Tag* t;
enum { value = sizeof(is_new_iter_cat(t)) == sizeof(type_traits::yes_type) };
};
#endif
} // namespace detail
#if 0
template <class Iterator>
struct return_category {
typedef typename detail::choose_return_category<Iterator>::type type;
@@ -170,6 +188,56 @@ namespace boost {
struct traversal_category {
typedef typename detail::choose_traversal_category<Iterator>::type type;
};
#else
namespace detail {
template <class NewCategoryTag>
struct get_return_category {
typedef typename NewCategoryTag::returns type;
};
template <class NewCategoryTag>
struct get_traversal_category {
typedef typename NewCategoryTag::traversal type;
};
template <class CategoryTag, class Value>
struct return_category_tag
{
typedef typename
mpl::apply_if<
is_new_iterator_tag<CategoryTag>
, get_return_category<CategoryTag>
, iter_category_to_return<CategoryTag, Value>
>::type type;
};
template <class CategoryTag, class Value>
struct traversal_category_tag
{
typedef typename
mpl::apply_if<
is_new_iterator_tag<CategoryTag>
, get_traversal_category<CategoryTag>
, iter_category_to_return<CategoryTag, Value>
>::type type;
};
} // namespace detail
template <class Iterator>
struct return_category {
typedef typename detail::return_category_tag<
typename detail::iterator_traits<Iterator>::iterator_category
, typename detail::iterator_traits<Iterator>::value_type>::type type;
};
template <class Iterator>
struct traversal_category {
typedef typename detail::traversal_category_tag<
typename detail::iterator_traits<Iterator>::iterator_category
, typename detail::iterator_traits<Iterator>::value_type>::type type;
};
#endif
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)

View File

@@ -26,8 +26,7 @@ namespace boost_concepts {
public:
typedef typename std::iterator_traits<Iterator>::value_type value_type;
typedef typename std::iterator_traits<Iterator>::reference reference;
typedef typename std::iterator_traits<Iterator>::iterator_category iterator_category;
typedef typename iterator_category::returns return_category;
typedef typename boost::return_category<Iterator>::type return_category;
void constraints() {
boost::function_requires< boost::SGIAssignableConcept<Iterator> >();
@@ -48,8 +47,7 @@ namespace boost_concepts {
template <typename Iterator, typename ValueType>
class WritableIteratorConcept {
public:
typedef typename std::iterator_traits<Iterator>::iterator_category iterator_category;
typedef typename iterator_category::returns return_category;
typedef typename boost::return_category<Iterator>::type return_category;
void constraints() {
boost::function_requires< boost::SGIAssignableConcept<Iterator> >();
@@ -71,8 +69,7 @@ namespace boost_concepts {
public:
typedef typename std::iterator_traits<Iterator>::value_type value_type;
typedef typename std::iterator_traits<Iterator>::reference reference;
typedef typename std::iterator_traits<Iterator>::iterator_category iterator_category;
typedef typename iterator_category::returns return_category;
typedef typename boost::return_category<Iterator>::type return_category;
void constraints() {
boost::function_requires< ReadableIteratorConcept<Iterator> >();
@@ -94,8 +91,7 @@ namespace boost_concepts {
public:
typedef typename std::iterator_traits<Iterator>::value_type value_type;
typedef typename std::iterator_traits<Iterator>::reference reference;
typedef typename std::iterator_traits<Iterator>::iterator_category iterator_category;
typedef typename iterator_category::returns return_category;
typedef typename boost::return_category<Iterator>::type return_category;
void constraints() {
boost::function_requires< ReadableIteratorConcept<Iterator> >();
@@ -119,8 +115,7 @@ namespace boost_concepts {
template <typename Iterator>
class ForwardTraversalConcept {
public:
typedef typename std::iterator_traits<Iterator>::iterator_category iterator_category;
typedef typename iterator_category::traversal traversal_category;
typedef typename boost::traversal_category<Iterator>::type traversal_category;
void constraints() {
boost::function_requires< boost::SGIAssignableConcept<Iterator> >();
@@ -139,8 +134,7 @@ namespace boost_concepts {
template <typename Iterator>
class BidirectionalTraversalConcept {
public:
typedef typename std::iterator_traits<Iterator>::iterator_category iterator_category;
typedef typename iterator_category::traversal traversal_category;
typedef typename boost::traversal_category<Iterator>::type traversal_category;
void constraints() {
boost::function_requires< ForwardTraversalConcept<Iterator> >();
@@ -157,8 +151,7 @@ namespace boost_concepts {
template <typename Iterator>
class RandomAccessTraversalConcept {
public:
typedef typename std::iterator_traits<Iterator>::iterator_category iterator_category;
typedef typename iterator_category::traversal traversal_category;
typedef typename boost::traversal_category<Iterator>::type traversal_category;
typedef typename std::iterator_traits<Iterator>::difference_type
difference_type;

View File

@@ -6,14 +6,13 @@
#include <boost/iterator/iterator_concepts.hpp>
#include <boost/operators.hpp>
#include <boost/static_assert.hpp> // remove
struct new_iterator
: public boost::iterator<std::random_access_iterator_tag, int>,
public boost::new_iterator_base
: public boost::iterator< boost::iterator_tag<
boost::mutable_lvalue_iterator_tag
, boost::random_access_traversal_tag>, int>
{
typedef boost::random_access_traversal_tag traversal_category;
typedef boost::mutable_lvalue_iterator_tag return_category;
int& operator*() const { return *m_x; }
new_iterator& operator++() { return *this; }
new_iterator operator++(int) { return *this; }
@@ -58,22 +57,22 @@ main()
boost::function_requires<
boost_concepts::MutableLvalueIteratorConcept<int*> >();
boost::function_requires<
boost_concepts::RandomAccessIteratorConcept<int*> >();
boost_concepts::RandomAccessTraversalConcept<int*> >();
boost::function_requires<
boost_concepts::ConstantLvalueIteratorConcept<const int*> >();
boost::function_requires<
boost_concepts::RandomAccessIteratorConcept<const int*> >();
boost_concepts::RandomAccessTraversalConcept<const int*> >();
#endif
boost::function_requires<
boost_concepts::MutableLvalueIteratorConcept<new_iterator> >();
boost::function_requires<
boost_concepts::RandomAccessIteratorConcept<new_iterator> >();
boost_concepts::RandomAccessTraversalConcept<new_iterator> >();
boost::function_requires<
boost_concepts::MutableLvalueIteratorConcept<old_iterator> >();
boost::function_requires<
boost_concepts::RandomAccessIteratorConcept<old_iterator> >();
boost_concepts::RandomAccessTraversalConcept<old_iterator> >();
return 0;
}