• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CATEGORY_OF_07202005_0308)
8 #define FUSION_CATEGORY_OF_07202005_0308
9 
10 #include <boost/fusion/support/config.hpp>
11 #include <boost/fusion/support/tag_of.hpp>
12 #include <boost/type_traits/is_base_of.hpp>
13 
14 namespace boost { namespace fusion
15 {
16     // Special tags:
17     struct boost_tuple_tag; // boost::tuples::tuple tag
18     struct boost_array_tag; // boost::array tag
19     struct mpl_sequence_tag; // mpl sequence tag
20     struct std_pair_tag; // std::pair tag
21 
22     struct incrementable_traversal_tag {};
23 
24     struct single_pass_traversal_tag
25         : incrementable_traversal_tag {};
26 
27     struct forward_traversal_tag
28         : single_pass_traversal_tag {};
29 
30     struct bidirectional_traversal_tag
31         : forward_traversal_tag {};
32 
33     struct random_access_traversal_tag
34         : bidirectional_traversal_tag {};
35 
36     struct associative_tag {};
37 
38     struct unbounded_tag {};
39 
40     namespace extension
41     {
42         template<typename Tag>
43         struct category_of_impl
44         {
45             template<typename T>
46             struct apply
47             {
48                 typedef typename T::category type;
49             };
50         };
51 
52         template <>
53         struct category_of_impl<boost_tuple_tag>;
54 
55         template <>
56         struct category_of_impl<boost_array_tag>;
57 
58         template <>
59         struct category_of_impl<mpl_sequence_tag>;
60 
61         template <>
62         struct category_of_impl<std_pair_tag>;
63     }
64 
65     namespace traits
66     {
67         template <typename T>
68         struct category_of
69             : extension::category_of_impl<typename fusion::detail::tag_of<T>::type>::
70                 template apply<T>
71         {};
72 
73         template <typename T>
74         struct is_associative
75             : is_base_of<
76                 associative_tag
77               , typename category_of<T>::type>
78         {};
79 
80         template <typename T>
81         struct is_incrementable
82             : is_base_of<
83                 incrementable_traversal_tag
84               , typename category_of<T>::type>
85         {};
86 
87         template <typename T>
88         struct is_single_pass
89             : is_base_of<
90                 single_pass_traversal_tag
91               , typename category_of<T>::type>
92         {};
93 
94         template <typename T>
95         struct is_forward
96             : is_base_of<
97                 forward_traversal_tag
98               , typename category_of<T>::type>
99         {};
100 
101         template <typename T>
102         struct is_bidirectional
103             : is_base_of<
104                 bidirectional_traversal_tag
105               , typename category_of<T>::type>
106         {};
107 
108         template <typename T>
109         struct is_random_access
110             : is_base_of<
111                 random_access_traversal_tag
112               , typename category_of<T>::type>
113         {};
114 
115         template <typename T>
116         struct is_unbounded
117             : is_base_of<
118                 unbounded_tag
119               , typename category_of<T>::type>
120         {};
121     }
122 }}
123 
124 #endif
125