File indexing completed on 2025-01-18 09:50:27
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_PROTO_FUNCTIONAL_STD_ITERATOR_HPP_EAN_27_08_2012
0010 #define BOOST_PROTO_FUNCTIONAL_STD_ITERATOR_HPP_EAN_27_08_2012
0011
0012 #include <iterator>
0013 #include <boost/type_traits/remove_const.hpp>
0014 #include <boost/type_traits/remove_reference.hpp>
0015 #include <boost/proto/proto_fwd.hpp>
0016
0017 namespace boost { namespace proto { namespace functional
0018 {
0019
0020
0021 struct advance
0022 {
0023 BOOST_PROTO_CALLABLE()
0024
0025 typedef void result_type;
0026
0027 template<typename InputIterator, typename Distance>
0028 void operator()(InputIterator &x, Distance n) const
0029 {
0030 std::advance(x, n);
0031 }
0032 };
0033
0034
0035 struct distance
0036 {
0037 BOOST_PROTO_CALLABLE()
0038
0039 template<typename Sig>
0040 struct result;
0041
0042 template<typename This, typename InputIter1, typename InputIter2>
0043 struct result<This(InputIter1, InputIter2)>
0044 {
0045 typedef
0046 typename std::iterator_traits<
0047 typename boost::remove_const<
0048 typename boost::remove_reference<InputIter1>::type
0049 >::type
0050 >::difference_type
0051 type;
0052 };
0053
0054 template<typename InputIterator>
0055 typename std::iterator_traits<InputIterator>::difference_type
0056 operator()(InputIterator first, InputIterator last) const
0057 {
0058 return std::distance(first, last);
0059 }
0060 };
0061
0062
0063 struct next
0064 {
0065 BOOST_PROTO_CALLABLE()
0066
0067 template<typename Sig>
0068 struct result;
0069
0070 template<typename This, typename ForwardIterator>
0071 struct result<This(ForwardIterator)>
0072 {
0073 typedef
0074 typename boost::remove_const<
0075 typename boost::remove_reference<ForwardIterator>::type
0076 >::type
0077 type;
0078 };
0079
0080 template<typename This, typename ForwardIterator, typename Distance>
0081 struct result<This(ForwardIterator, Distance)>
0082 {
0083 typedef
0084 typename boost::remove_const<
0085 typename boost::remove_reference<ForwardIterator>::type
0086 >::type
0087 type;
0088 };
0089
0090 template<typename ForwardIterator>
0091 ForwardIterator operator()(ForwardIterator x) const
0092 {
0093 return std::advance(
0094 x
0095 , static_cast<typename std::iterator_traits<ForwardIterator>::difference_type>(1)
0096 );
0097 }
0098
0099 template<typename ForwardIterator>
0100 ForwardIterator operator()(
0101 ForwardIterator x
0102 , typename std::iterator_traits<ForwardIterator>::difference_type n
0103 ) const
0104 {
0105 return std::advance(x, n);
0106 }
0107 };
0108
0109
0110 struct prior
0111 {
0112 BOOST_PROTO_CALLABLE()
0113
0114 template<typename Sig>
0115 struct result;
0116
0117 template<typename This, typename BidirectionalIterator>
0118 struct result<This(BidirectionalIterator)>
0119 {
0120 typedef
0121 typename boost::remove_const<
0122 typename boost::remove_reference<BidirectionalIterator>::type
0123 >::type
0124 type;
0125 };
0126
0127 template<typename This, typename BidirectionalIterator, typename Distance>
0128 struct result<This(BidirectionalIterator, Distance)>
0129 {
0130 typedef
0131 typename boost::remove_const<
0132 typename boost::remove_reference<BidirectionalIterator>::type
0133 >::type
0134 type;
0135 };
0136
0137 template<typename BidirectionalIterator>
0138 BidirectionalIterator operator()(BidirectionalIterator x) const
0139 {
0140 return std::advance(
0141 x
0142 , -static_cast<typename std::iterator_traits<BidirectionalIterator>::difference_type>(1)
0143 );
0144 }
0145
0146 template<typename BidirectionalIterator>
0147 BidirectionalIterator operator()(
0148 BidirectionalIterator x
0149 , typename std::iterator_traits<BidirectionalIterator>::difference_type n
0150 ) const
0151 {
0152 return std::advance(x, -n);
0153 }
0154 };
0155
0156 }}}
0157
0158 #endif