Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:51:17

0001 //  Copyright Neil Groves 2009. Use, modification and
0002 //  distribution is subject to the Boost Software License, Version
0003 //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
0004 //  http://www.boost.org/LICENSE_1_0.txt)
0005 //
0006 //
0007 // For more information, see http://www.boost.org/libs/range/
0008 //
0009 #ifndef BOOST_RANGE_DETAIL_RANGE_RETURN_HPP_INCLUDED
0010 #define BOOST_RANGE_DETAIL_RANGE_RETURN_HPP_INCLUDED
0011 
0012 #include <boost/range/begin.hpp>
0013 #include <boost/range/end.hpp>
0014 #include <boost/range/iterator_range.hpp>
0015 #include <boost/next_prior.hpp>
0016 
0017 namespace boost
0018 {
0019     enum range_return_value
0020     {
0021         // (*) indicates the most common values
0022         return_found,       // only the found resulting iterator (*)
0023         return_next,        // next(found) iterator
0024         return_prior,       // prior(found) iterator
0025         return_begin_found, // [begin, found) range (*)
0026         return_begin_next,  // [begin, next(found)) range
0027         return_begin_prior, // [begin, prior(found)) range
0028         return_found_end,   // [found, end) range (*)
0029         return_next_end,    // [next(found), end) range
0030         return_prior_end,   // [prior(found), end) range
0031         return_begin_end    // [begin, end) range
0032     };
0033 
0034     template< class SinglePassRange, range_return_value >
0035     struct range_return
0036     {
0037         typedef boost::iterator_range<
0038             BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type > type;
0039 
0040         static type pack(BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type found,
0041                          SinglePassRange& rng)
0042         {
0043             return type(found, boost::end(rng));
0044         }
0045     };
0046 
0047     template< class SinglePassRange >
0048     struct range_return< SinglePassRange, return_found >
0049     {
0050         typedef BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type type;
0051 
0052         static type pack(type found, SinglePassRange&)
0053         {
0054             return found;
0055         }
0056     };
0057 
0058     template< class SinglePassRange >
0059     struct range_return< SinglePassRange, return_next >
0060     {
0061         typedef BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type type;
0062 
0063         static type pack(type found, SinglePassRange& rng)
0064         {
0065             return found == boost::end(rng)
0066                 ? found
0067                 : boost::next(found);
0068         }
0069     };
0070 
0071     template< class BidirectionalRange >
0072     struct range_return< BidirectionalRange, return_prior >
0073     {
0074         typedef BOOST_DEDUCED_TYPENAME range_iterator<BidirectionalRange>::type type;
0075 
0076         static type pack(type found, BidirectionalRange& rng)
0077         {
0078             return found == boost::begin(rng)
0079                 ? found
0080                 : boost::prior(found);
0081         }
0082     };
0083 
0084     template< class SinglePassRange >
0085     struct range_return< SinglePassRange, return_begin_found >
0086     {
0087         typedef boost::iterator_range<
0088             BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type > type;
0089 
0090         static type pack(BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type found,
0091                          SinglePassRange& rng)
0092         {
0093             return type(boost::begin(rng), found);
0094         }
0095     };
0096 
0097     template< class SinglePassRange >
0098     struct range_return< SinglePassRange, return_begin_next >
0099     {
0100         typedef boost::iterator_range<
0101             BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type > type;
0102 
0103         static type pack(BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type found,
0104                          SinglePassRange& rng)
0105         {
0106             return type( boost::begin(rng), 
0107                          found == boost::end(rng) ? found : boost::next(found) );
0108         }
0109     };
0110 
0111     template< class BidirectionalRange >
0112     struct range_return< BidirectionalRange, return_begin_prior >
0113     {
0114         typedef boost::iterator_range<
0115             BOOST_DEDUCED_TYPENAME range_iterator<BidirectionalRange>::type > type;
0116 
0117         static type pack(BOOST_DEDUCED_TYPENAME range_iterator<BidirectionalRange>::type found,
0118                          BidirectionalRange& rng)
0119         {
0120             return type( boost::begin(rng),
0121                          found == boost::begin(rng) ? found : boost::prior(found) );
0122         }
0123     };
0124 
0125     template< class SinglePassRange >
0126     struct range_return< SinglePassRange, return_found_end >
0127     {
0128         typedef boost::iterator_range<
0129             BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type > type;
0130 
0131         static type pack(BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type found,
0132                          SinglePassRange& rng)
0133         {
0134             return type(found, boost::end(rng));
0135         }
0136     };
0137 
0138     template< class SinglePassRange >
0139     struct range_return< SinglePassRange, return_next_end >
0140     {
0141         typedef boost::iterator_range<
0142             BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type > type;
0143 
0144         static type pack(BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type found,
0145                          SinglePassRange& rng)
0146         {
0147             return type( found == boost::end(rng) ? found : boost::next(found),
0148                          boost::end(rng) );
0149         }
0150     };
0151 
0152     template< class BidirectionalRange >
0153     struct range_return< BidirectionalRange, return_prior_end >
0154     {
0155         typedef boost::iterator_range<
0156             BOOST_DEDUCED_TYPENAME range_iterator<BidirectionalRange>::type > type;
0157 
0158         static type pack(BOOST_DEDUCED_TYPENAME range_iterator<BidirectionalRange>::type found,
0159                          BidirectionalRange& rng)
0160         {
0161             return type( found == boost::begin(rng) ? found : boost::prior(found),
0162                          boost::end(rng) );
0163         }
0164     };
0165 
0166     template< class SinglePassRange >
0167     struct range_return< SinglePassRange, return_begin_end >
0168     {
0169         typedef boost::iterator_range<
0170             BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type > type;
0171 
0172         static type pack(BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type,
0173                          SinglePassRange& rng)
0174         {
0175             return type(boost::begin(rng), boost::end(rng));
0176         }
0177     };
0178 
0179 }
0180 
0181 #endif // include guard