]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 2001-2011 Joel de Guzman | |
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(FUSION_SIZE_05052005_0214) | |
8 | #define FUSION_SIZE_05052005_0214 | |
9 | ||
10 | #include <boost/fusion/support/config.hpp> | |
11 | #include <boost/utility/enable_if.hpp> | |
12 | #include <boost/mpl/if.hpp> | |
13 | #include <boost/mpl/int.hpp> | |
14 | #include <boost/fusion/sequence/intrinsic_fwd.hpp> | |
15 | #include <boost/fusion/support/tag_of.hpp> | |
16 | #include <boost/fusion/support/is_segmented.hpp> | |
17 | #include <boost/fusion/sequence/intrinsic/detail/segmented_size.hpp> | |
18 | ||
19 | namespace boost { namespace fusion | |
20 | { | |
21 | // Special tags: | |
22 | struct sequence_facade_tag; | |
23 | struct boost_tuple_tag; // boost::tuples::tuple tag | |
24 | struct boost_array_tag; // boost::array tag | |
25 | struct mpl_sequence_tag; // mpl sequence tag | |
26 | struct std_pair_tag; // std::pair tag | |
27 | ||
28 | namespace extension | |
29 | { | |
30 | template <typename Tag> | |
31 | struct size_impl | |
32 | { | |
33 | template<typename Sequence> | |
34 | struct unsegmented_size : Sequence::size {}; | |
35 | ||
36 | template <typename Sequence> | |
37 | struct apply | |
38 | : mpl::if_< | |
39 | traits::is_segmented<Sequence> | |
40 | , detail::segmented_size<Sequence> | |
41 | , unsegmented_size<Sequence> | |
42 | >::type | |
43 | {}; | |
44 | }; | |
45 | ||
46 | template <> | |
47 | struct size_impl<sequence_facade_tag> | |
48 | { | |
49 | template <typename Sequence> | |
50 | struct apply : Sequence::template size<Sequence> {}; | |
51 | }; | |
52 | ||
53 | template <> | |
54 | struct size_impl<boost_tuple_tag>; | |
55 | ||
56 | template <> | |
57 | struct size_impl<boost_array_tag>; | |
58 | ||
59 | template <> | |
60 | struct size_impl<mpl_sequence_tag>; | |
61 | ||
62 | template <> | |
63 | struct size_impl<std_pair_tag>; | |
64 | } | |
65 | ||
66 | namespace result_of | |
67 | { | |
68 | template <typename Sequence> | |
69 | struct size | |
70 | : mpl::int_< | |
71 | extension::size_impl<typename detail::tag_of<Sequence>::type> | |
72 | ::template apply<Sequence>::type::value | |
73 | > {}; | |
74 | } | |
75 | ||
76 | template <typename Sequence> | |
77 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED | |
78 | inline typename result_of::size<Sequence>::type | |
79 | size(Sequence const&) | |
80 | { | |
81 | typedef typename result_of::size<Sequence>::type result; | |
82 | return result(); | |
83 | } | |
84 | }} | |
85 | ||
86 | #endif |