1 | // Boost.Range library |
2 | // |
3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and |
4 | // distribution is subject to the Boost Software License, Version |
5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
6 | // http://www.boost.org/LICENSE_1_0.txt) |
7 | // |
8 | // For more information, see http://www.boost.org/libs/range/ |
9 | // |
10 | |
11 | #ifndef BOOST_RANGE_DETAIL_COMMON_HPP |
12 | #define BOOST_RANGE_DETAIL_COMMON_HPP |
13 | |
14 | #if defined(_MSC_VER) |
15 | # pragma once |
16 | #endif |
17 | |
18 | #include <boost/range/config.hpp> |
19 | #include <boost/range/detail/sfinae.hpp> |
20 | #include <boost/type_traits/is_void.hpp> |
21 | #include <boost/type_traits/detail/ice_or.hpp> |
22 | #include <boost/mpl/if.hpp> |
23 | #include <boost/mpl/int.hpp> |
24 | #include <cstddef> |
25 | |
26 | ////////////////////////////////////////////////////////////////////////////// |
27 | // missing partial specialization workaround. |
28 | ////////////////////////////////////////////////////////////////////////////// |
29 | |
30 | namespace boost |
31 | { |
32 | namespace range_detail |
33 | { |
34 | // 1 = std containers |
35 | // 2 = std::pair |
36 | // 3 = const std::pair |
37 | // 4 = array |
38 | // 5 = const array |
39 | // 6 = char array |
40 | // 7 = wchar_t array |
41 | // 8 = char* |
42 | // 9 = const char* |
43 | // 10 = whar_t* |
44 | // 11 = const wchar_t* |
45 | // 12 = string |
46 | |
47 | typedef mpl::int_<1>::type std_container_; |
48 | typedef mpl::int_<2>::type std_pair_; |
49 | typedef mpl::int_<3>::type const_std_pair_; |
50 | typedef mpl::int_<4>::type array_; |
51 | typedef mpl::int_<5>::type const_array_; |
52 | typedef mpl::int_<6>::type char_array_; |
53 | typedef mpl::int_<7>::type wchar_t_array_; |
54 | typedef mpl::int_<8>::type char_ptr_; |
55 | typedef mpl::int_<9>::type const_char_ptr_; |
56 | typedef mpl::int_<10>::type wchar_t_ptr_; |
57 | typedef mpl::int_<11>::type const_wchar_t_ptr_; |
58 | typedef mpl::int_<12>::type string_; |
59 | |
60 | template< typename C > |
61 | struct range_helper |
62 | { |
63 | static C* c; |
64 | static C ptr; |
65 | |
66 | BOOST_STATIC_CONSTANT( bool, is_pair_ = sizeof( boost::range_detail::is_pair_impl( c ) ) == sizeof( yes_type ) ); |
67 | BOOST_STATIC_CONSTANT( bool, is_char_ptr_ = sizeof( boost::range_detail::is_char_ptr_impl( ptr ) ) == sizeof( yes_type ) ); |
68 | BOOST_STATIC_CONSTANT( bool, is_const_char_ptr_ = sizeof( boost::range_detail::is_const_char_ptr_impl( ptr ) ) == sizeof( yes_type ) ); |
69 | BOOST_STATIC_CONSTANT( bool, is_wchar_t_ptr_ = sizeof( boost::range_detail::is_wchar_t_ptr_impl( ptr ) ) == sizeof( yes_type ) ); |
70 | BOOST_STATIC_CONSTANT( bool, is_const_wchar_t_ptr_ = sizeof( boost::range_detail::is_const_wchar_t_ptr_impl( ptr ) ) == sizeof( yes_type ) ); |
71 | BOOST_STATIC_CONSTANT( bool, is_char_array_ = sizeof( boost::range_detail::is_char_array_impl( ptr ) ) == sizeof( yes_type ) ); |
72 | BOOST_STATIC_CONSTANT( bool, is_wchar_t_array_ = sizeof( boost::range_detail::is_wchar_t_array_impl( ptr ) ) == sizeof( yes_type ) ); |
73 | BOOST_STATIC_CONSTANT( bool, is_string_ = (boost::type_traits::ice_or<is_const_char_ptr_, is_const_wchar_t_ptr_>::value )); |
74 | BOOST_STATIC_CONSTANT( bool, is_array_ = boost::is_array<C>::value ); |
75 | |
76 | }; |
77 | |
78 | template< typename C > |
79 | class range |
80 | { |
81 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_pair_, |
82 | boost::range_detail::std_pair_, |
83 | void >::type pair_t; |
84 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_array_, |
85 | boost::range_detail::array_, |
86 | pair_t >::type array_t; |
87 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_string_, |
88 | boost::range_detail::string_, |
89 | array_t >::type string_t; |
90 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_const_char_ptr_, |
91 | boost::range_detail::const_char_ptr_, |
92 | string_t >::type const_char_ptr_t; |
93 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_char_ptr_, |
94 | boost::range_detail::char_ptr_, |
95 | const_char_ptr_t >::type char_ptr_t; |
96 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_const_wchar_t_ptr_, |
97 | boost::range_detail::const_wchar_t_ptr_, |
98 | char_ptr_t >::type const_wchar_ptr_t; |
99 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_wchar_t_ptr_, |
100 | boost::range_detail::wchar_t_ptr_, |
101 | const_wchar_ptr_t >::type wchar_ptr_t; |
102 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_wchar_t_array_, |
103 | boost::range_detail::wchar_t_array_, |
104 | wchar_ptr_t >::type wchar_array_t; |
105 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_char_array_, |
106 | boost::range_detail::char_array_, |
107 | wchar_array_t >::type char_array_t; |
108 | public: |
109 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::is_void<char_array_t>::value, |
110 | boost::range_detail::std_container_, |
111 | char_array_t >::type type; |
112 | }; // class 'range' |
113 | } |
114 | } |
115 | |
116 | #endif |
117 | |
118 | |