Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:31:07

0001 /*=============================================================================
0002     Copyright (c) 2001-2011 Joel de Guzman
0003 
0004     Distributed under the Boost Software License, Version 1.0. (See accompanying
0005     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 ==============================================================================*/
0007 #if !defined(FUSION_BOOST_TUPLE_ITERATOR_09262006_1851)
0008 #define FUSION_BOOST_TUPLE_ITERATOR_09262006_1851
0009 
0010 #include <boost/fusion/support/config.hpp>
0011 #include <boost/fusion/iterator/iterator_facade.hpp>
0012 #include <boost/type_traits/is_const.hpp>
0013 #include <boost/type_traits/add_const.hpp>
0014 #include <boost/mpl/identity.hpp>
0015 #include <boost/mpl/if.hpp>
0016 #include <boost/mpl/eval_if.hpp>
0017 #include <boost/mpl/or.hpp>
0018 #include <boost/mpl/plus.hpp>
0019 #include <boost/mpl/int.hpp>
0020 #include <boost/mpl/apply.hpp>
0021 #include <boost/tuple/tuple.hpp>
0022 
0023 namespace boost { namespace fusion
0024 {
0025     struct forward_traversal_tag;
0026 
0027     namespace detail
0028     {
0029         template <typename T>
0030         struct boost_tuple_is_empty : mpl::false_ {};
0031 
0032         template <>
0033         struct boost_tuple_is_empty<tuples::null_type> : mpl::true_ {};
0034 
0035         template <>
0036         struct boost_tuple_is_empty<tuples::null_type const> : mpl::true_ {};
0037 
0038         template <>
0039         struct boost_tuple_is_empty<tuples::tuple<> > : mpl::true_ {};
0040 
0041         template <>
0042         struct boost_tuple_is_empty<tuples::tuple<> const> : mpl::true_ {};
0043     }
0044 
0045     template <typename Cons>
0046     struct boost_tuple_iterator_identity;
0047 
0048 #ifdef _MSC_VER
0049 #  pragma warning(push)
0050 #  pragma warning(disable: 4512) // assignment operator could not be generated.
0051 #endif
0052     template <typename Cons = tuples::null_type>
0053     struct boost_tuple_iterator
0054         : iterator_facade<boost_tuple_iterator<Cons>, forward_traversal_tag>
0055     {
0056         typedef Cons cons_type;
0057 
0058         typedef boost_tuple_iterator_identity<
0059             typename add_const<Cons>::type> identity;
0060 
0061         BOOST_FUSION_GPU_ENABLED
0062         explicit boost_tuple_iterator(Cons& in_cons)
0063             : cons(in_cons) {}
0064         Cons& cons;
0065 
0066         template <typename Iterator>
0067         struct value_of : mpl::identity<typename Iterator::cons_type::head_type> {};
0068 
0069         template <typename Iterator>
0070         struct deref
0071         {
0072             typedef typename value_of<Iterator>::type element;
0073 
0074             typedef typename
0075                 mpl::if_<
0076                     is_const<typename Iterator::cons_type>
0077                   , typename tuples::access_traits<element>::const_type
0078                   , typename tuples::access_traits<element>::non_const_type
0079                 >::type
0080             type;
0081 
0082             BOOST_FUSION_GPU_ENABLED
0083             static type
0084             call(Iterator const& iter)
0085             {
0086                 return iter.cons.get_head();
0087             }
0088         };
0089 
0090         template <typename Iterator>
0091         struct next
0092         {
0093             typedef typename Iterator::cons_type cons_type;
0094             typedef typename cons_type::tail_type tail_type;
0095 
0096             typedef boost_tuple_iterator<
0097                 typename mpl::eval_if<
0098                     is_const<cons_type>
0099                   , add_const<tail_type>
0100                   , mpl::identity<tail_type>
0101                 >::type>
0102             type;
0103 
0104             BOOST_FUSION_GPU_ENABLED
0105             static type
0106             call(Iterator const& iter)
0107             {
0108                 return type(iter.cons.get_tail());
0109             }
0110         };
0111 
0112         template <typename I1, typename I2>
0113         struct distance;
0114 
0115         // detail
0116         template <typename I1, typename I2>
0117         struct lazy_next_distance
0118         {
0119             typedef
0120                 typename mpl::plus<
0121                     mpl::int_<1>,
0122                     typename distance<
0123                         typename next<I1>::type,
0124                         I2
0125                     >::type
0126                 >::type type;
0127         };
0128 
0129         template <typename I1, typename I2>
0130         struct distance
0131         {
0132             typedef typename mpl::eval_if<
0133                 boost::is_same<I1, I2>,
0134                 mpl::int_<0>,
0135                 lazy_next_distance<I1, I2>
0136             >::type type;
0137 
0138             BOOST_FUSION_GPU_ENABLED
0139             static type
0140             call(I1 const&, I2 const&)
0141             {
0142                 return type();
0143             }
0144         };
0145 
0146         template <typename I1, typename I2>
0147         struct equal_to
0148             : is_same<typename I1::identity, typename I2::identity>
0149         {};
0150     };
0151 #ifdef _MSC_VER
0152 #  pragma warning(pop)
0153 #endif
0154 
0155     template <typename Null>
0156     struct boost_tuple_null_iterator
0157         : iterator_facade<boost_tuple_iterator<Null>, forward_traversal_tag>
0158     {
0159         typedef Null cons_type;
0160 
0161         typedef boost_tuple_iterator_identity<
0162             typename add_const<Null>::type> identity;
0163 
0164         template <typename I1, typename I2>
0165         struct equal_to
0166             : mpl::or_<
0167                 is_same<I1, I2>
0168               , mpl::and_<
0169                     detail::boost_tuple_is_empty<typename I1::cons_type>
0170                   , detail::boost_tuple_is_empty<typename I2::cons_type>
0171                 >
0172             >
0173         {};
0174     };
0175 
0176     template <>
0177     struct boost_tuple_iterator<tuples::null_type>
0178         : boost_tuple_null_iterator<tuples::null_type>
0179     {
0180         template <typename Cons>
0181         BOOST_FUSION_GPU_ENABLED
0182         explicit boost_tuple_iterator(Cons const&) {}
0183     };
0184 
0185     template <>
0186     struct boost_tuple_iterator<tuples::null_type const>
0187         : boost_tuple_null_iterator<tuples::null_type const>
0188     {
0189         template <typename Cons>
0190         BOOST_FUSION_GPU_ENABLED
0191         explicit boost_tuple_iterator(Cons const&) {}
0192     };
0193 
0194     template <>
0195     struct boost_tuple_iterator<tuples::tuple<> >
0196         : boost_tuple_null_iterator<tuples::tuple<> >
0197     {
0198         template <typename Cons>
0199         BOOST_FUSION_GPU_ENABLED
0200         explicit boost_tuple_iterator(Cons const&) {}
0201     };
0202 
0203     template <>
0204     struct boost_tuple_iterator<tuples::tuple<> const>
0205         : boost_tuple_null_iterator<tuples::tuple<> const>
0206     {
0207         template <typename Cons>
0208         BOOST_FUSION_GPU_ENABLED
0209         explicit boost_tuple_iterator(Cons const&) {}
0210     };
0211 }}
0212 
0213 #ifdef BOOST_FUSION_WORKAROUND_FOR_LWG_2408
0214 namespace std
0215 {
0216     template <typename Cons>
0217     struct iterator_traits< ::boost::fusion::boost_tuple_iterator<Cons> >
0218     { };
0219 }
0220 #endif
0221 
0222 #endif
0223 
0224