/////////////////////////////////////////////////////////////////////////////// /// \file iterator.hpp /// Proto callables for std functions found in \ // // Copyright 2012 Eric Niebler. Distributed under 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 ACTIV_BOOST_PROTO_FUNCTIONAL_STD_ITERATOR_HPP_EAN_27_08_2012 #define ACTIV_BOOST_PROTO_FUNCTIONAL_STD_ITERATOR_HPP_EAN_27_08_2012 #include #include #include #include namespace Boost { namespace proto { namespace functional { // A PolymorphicFunctionObject wrapping std::advance struct advance { ACTIV_BOOST_PROTO_CALLABLE() typedef void result_type; template void operator()(InputIterator &x, Distance n) const { std::advance(x, n); } }; // A PolymorphicFunctionObject wrapping std::distance struct distance { ACTIV_BOOST_PROTO_CALLABLE() template struct result; template struct result { typedef typename std::iterator_traits< typename Boost::remove_const< typename Boost::remove_reference::type >::type >::difference_type type; }; template typename std::iterator_traits::difference_type operator()(InputIterator first, InputIterator last) const { return std::distance(first, last); } }; // A PolymorphicFunctionObject wrapping std::next struct next { ACTIV_BOOST_PROTO_CALLABLE() template struct result; template struct result { typedef typename Boost::remove_const< typename Boost::remove_reference::type >::type type; }; template struct result { typedef typename Boost::remove_const< typename Boost::remove_reference::type >::type type; }; template ForwardIterator operator()(ForwardIterator x) const { return std::advance( x , static_cast::difference_type>(1) ); } template ForwardIterator operator()( ForwardIterator x , typename std::iterator_traits::difference_type n ) const { return std::advance(x, n); } }; // A PolymorphicFunctionObject wrapping std::prior struct prior { ACTIV_BOOST_PROTO_CALLABLE() template struct result; template struct result { typedef typename Boost::remove_const< typename Boost::remove_reference::type >::type type; }; template struct result { typedef typename Boost::remove_const< typename Boost::remove_reference::type >::type type; }; template BidirectionalIterator operator()(BidirectionalIterator x) const { return std::advance( x , -static_cast::difference_type>(1) ); } template BidirectionalIterator operator()( BidirectionalIterator x , typename std::iterator_traits::difference_type n ) const { return std::advance(x, -n); } }; }}} #endif