| 1 | /*============================================================================= |
|---|---|
| 2 | Copyright (c) 2011 Eric Niebler |
| 3 | |
| 4 | Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 5 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | ==============================================================================*/ |
| 7 | #if !defined(BOOST_FUSION_SEGMENTED_SIZE_08112006_1141) |
| 8 | #define BOOST_FUSION_SEGMENTED_SIZE_08112006_1141 |
| 9 | |
| 10 | #include <boost/fusion/support/config.hpp> |
| 11 | #include <boost/type_traits/add_const.hpp> |
| 12 | #include <boost/type_traits/remove_reference.hpp> |
| 13 | #include <boost/mpl/fold.hpp> |
| 14 | #include <boost/mpl/plus.hpp> |
| 15 | #include <boost/mpl/size_t.hpp> |
| 16 | #include <boost/mpl/placeholders.hpp> |
| 17 | #include <boost/fusion/sequence/intrinsic_fwd.hpp> |
| 18 | #include <boost/fusion/mpl/begin.hpp> |
| 19 | #include <boost/fusion/mpl/end.hpp> |
| 20 | #include <boost/fusion/support/is_segmented.hpp> |
| 21 | |
| 22 | namespace boost { namespace fusion { namespace detail |
| 23 | { |
| 24 | /////////////////////////////////////////////////////////////////////////// |
| 25 | // calculates the size of any segmented data structure. |
| 26 | template<typename Sequence> |
| 27 | struct segmented_size; |
| 28 | |
| 29 | /////////////////////////////////////////////////////////////////////////// |
| 30 | template<typename Sequence, bool IsSegmented = traits::is_segmented<Sequence>::value> |
| 31 | struct segmented_size_impl |
| 32 | : mpl::fold< |
| 33 | typename remove_reference< |
| 34 | typename add_const< |
| 35 | typename result_of::segments<Sequence>::type |
| 36 | >::type |
| 37 | >::type |
| 38 | , mpl::size_t<0> |
| 39 | , mpl::plus<mpl::_1, segmented_size<remove_reference<mpl::_2> > > |
| 40 | >::type |
| 41 | {}; |
| 42 | |
| 43 | template<typename Sequence> |
| 44 | struct segmented_size_impl<Sequence, false> |
| 45 | : result_of::size<Sequence>::type |
| 46 | {}; |
| 47 | |
| 48 | template<typename Sequence> |
| 49 | struct segmented_size |
| 50 | : segmented_size_impl<Sequence> |
| 51 | {}; |
| 52 | |
| 53 | }}} |
| 54 | |
| 55 | #endif |
| 56 |
