forked from boostorg/iterator
Added projection support.
[SVN r1198]
This commit is contained in:
@@ -12,6 +12,11 @@
|
|||||||
#include <boost/iterator.hpp>
|
#include <boost/iterator.hpp>
|
||||||
#include <boost/iterator/iterator_adaptor.hpp>
|
#include <boost/iterator/iterator_adaptor.hpp>
|
||||||
#include <boost/iterator/iterator_categories.hpp>
|
#include <boost/iterator/iterator_categories.hpp>
|
||||||
|
#include <boost/result_of.hpp>
|
||||||
|
#include <boost/type_traits/is_const.hpp>
|
||||||
|
#include <boost/type_traits/is_reference.hpp>
|
||||||
|
#include <boost/type_traits/remove_const.hpp>
|
||||||
|
#include <boost/type_traits/remove_reference.hpp>
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
@@ -22,19 +27,41 @@ namespace boost
|
|||||||
{
|
{
|
||||||
// Given the transform iterator's transformation and iterator, this
|
// Given the transform iterator's transformation and iterator, this
|
||||||
// is the type used as its traits.
|
// is the type used as its traits.
|
||||||
template <class AdaptableUnaryFunction, class Iterator>
|
template <class UnaryFunction, class Iterator>
|
||||||
struct transform_iterator_base
|
struct transform_iterator_base
|
||||||
{
|
{
|
||||||
typedef iterator_adaptor<
|
private:
|
||||||
transform_iterator<AdaptableUnaryFunction, Iterator>
|
typedef typename UnaryFunction::result_type result_type;
|
||||||
, Iterator
|
|
||||||
, typename AdaptableUnaryFunction::result_type
|
typedef typename remove_reference< result_type >::type cv_value_type;
|
||||||
, iterator_tag<
|
typedef typename remove_cv< cv_value_type >::type value_type;
|
||||||
readable_iterator_tag
|
|
||||||
, typename traversal_category<Iterator>::type
|
typedef typename mpl::if_<
|
||||||
>
|
is_reference< result_type >
|
||||||
, typename AdaptableUnaryFunction::result_type
|
, typename mpl::if_<
|
||||||
> type;
|
is_const< cv_value_type >
|
||||||
|
, readable_lvalue_iterator_tag
|
||||||
|
, writable_lvalue_iterator_tag
|
||||||
|
>::type
|
||||||
|
, readable_iterator_tag
|
||||||
|
>::type maximum_access_tag;
|
||||||
|
|
||||||
|
typedef typename minimum_category<
|
||||||
|
maximum_access_tag
|
||||||
|
, typename access_category<Iterator>::type
|
||||||
|
>::type access_category;
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef iterator_adaptor<
|
||||||
|
transform_iterator<UnaryFunction, Iterator>
|
||||||
|
, Iterator
|
||||||
|
, cv_value_type
|
||||||
|
, iterator_tag<
|
||||||
|
access_category
|
||||||
|
, typename traversal_category<Iterator>::type
|
||||||
|
>
|
||||||
|
, result_type
|
||||||
|
> type;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,14 +92,20 @@ namespace boost
|
|||||||
{ return m_f; }
|
{ return m_f; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typename super_t::value_type dereference() const
|
typename super_t::reference dereference() const
|
||||||
{ return m_f(super_t::dereference()); }
|
{ return m_f(*this->base()); }
|
||||||
|
|
||||||
// Probably should be the initial base class so it can be
|
// Probably should be the initial base class so it can be
|
||||||
// optimized away via EBO if it is an empty class.
|
// optimized away via EBO if it is an empty class.
|
||||||
AdaptableUnaryFunction m_f;
|
AdaptableUnaryFunction m_f;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class UnaryFunction, class Iterator>
|
||||||
|
transform_iterator<UnaryFunction, Iterator> make_transform_iterator(Iterator it, UnaryFunction fun)
|
||||||
|
{
|
||||||
|
return transform_iterator<UnaryFunction, Iterator>(it, fun);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
#endif // BOOST_TRANSFORM_ITERATOR_23022003THW_HPP
|
#endif // BOOST_TRANSFORM_ITERATOR_23022003THW_HPP
|
||||||
|
Reference in New Issue
Block a user