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