Brian Silverman | 598d029 | 2018-08-04 23:56:47 -0700 | [diff] [blame^] | 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/mpl/if.hpp> |
| 22 | #include <boost/mpl/int.hpp> |
| 23 | #include <cstddef> |
| 24 | |
| 25 | ////////////////////////////////////////////////////////////////////////////// |
| 26 | // missing partial specialization workaround. |
| 27 | ////////////////////////////////////////////////////////////////////////////// |
| 28 | |
| 29 | namespace boost |
| 30 | { |
| 31 | namespace range_detail |
| 32 | { |
| 33 | // 1 = std containers |
| 34 | // 2 = std::pair |
| 35 | // 3 = const std::pair |
| 36 | // 4 = array |
| 37 | // 5 = const array |
| 38 | // 6 = char array |
| 39 | // 7 = wchar_t array |
| 40 | // 8 = char* |
| 41 | // 9 = const char* |
| 42 | // 10 = whar_t* |
| 43 | // 11 = const wchar_t* |
| 44 | // 12 = string |
| 45 | |
| 46 | typedef mpl::int_<1>::type std_container_; |
| 47 | typedef mpl::int_<2>::type std_pair_; |
| 48 | typedef mpl::int_<3>::type const_std_pair_; |
| 49 | typedef mpl::int_<4>::type array_; |
| 50 | typedef mpl::int_<5>::type const_array_; |
| 51 | typedef mpl::int_<6>::type char_array_; |
| 52 | typedef mpl::int_<7>::type wchar_t_array_; |
| 53 | typedef mpl::int_<8>::type char_ptr_; |
| 54 | typedef mpl::int_<9>::type const_char_ptr_; |
| 55 | typedef mpl::int_<10>::type wchar_t_ptr_; |
| 56 | typedef mpl::int_<11>::type const_wchar_t_ptr_; |
| 57 | typedef mpl::int_<12>::type string_; |
| 58 | |
| 59 | template< typename C > |
| 60 | struct range_helper |
| 61 | { |
| 62 | static C* c; |
| 63 | static C ptr; |
| 64 | |
| 65 | BOOST_STATIC_CONSTANT( bool, is_pair_ = sizeof( boost::range_detail::is_pair_impl( c ) ) == sizeof( yes_type ) ); |
| 66 | BOOST_STATIC_CONSTANT( bool, is_char_ptr_ = sizeof( boost::range_detail::is_char_ptr_impl( ptr ) ) == sizeof( yes_type ) ); |
| 67 | BOOST_STATIC_CONSTANT( bool, is_const_char_ptr_ = sizeof( boost::range_detail::is_const_char_ptr_impl( ptr ) ) == sizeof( yes_type ) ); |
| 68 | BOOST_STATIC_CONSTANT( bool, is_wchar_t_ptr_ = sizeof( boost::range_detail::is_wchar_t_ptr_impl( ptr ) ) == sizeof( yes_type ) ); |
| 69 | BOOST_STATIC_CONSTANT( bool, is_const_wchar_t_ptr_ = sizeof( boost::range_detail::is_const_wchar_t_ptr_impl( ptr ) ) == sizeof( yes_type ) ); |
| 70 | BOOST_STATIC_CONSTANT( bool, is_char_array_ = sizeof( boost::range_detail::is_char_array_impl( ptr ) ) == sizeof( yes_type ) ); |
| 71 | BOOST_STATIC_CONSTANT( bool, is_wchar_t_array_ = sizeof( boost::range_detail::is_wchar_t_array_impl( ptr ) ) == sizeof( yes_type ) ); |
| 72 | BOOST_STATIC_CONSTANT( bool, is_string_ = (is_const_char_ptr_ || is_const_wchar_t_ptr_)); |
| 73 | BOOST_STATIC_CONSTANT( bool, is_array_ = boost::is_array<C>::value ); |
| 74 | |
| 75 | }; |
| 76 | |
| 77 | template< typename C > |
| 78 | class range |
| 79 | { |
| 80 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_pair_, |
| 81 | boost::range_detail::std_pair_, |
| 82 | void >::type pair_t; |
| 83 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_array_, |
| 84 | boost::range_detail::array_, |
| 85 | pair_t >::type array_t; |
| 86 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_string_, |
| 87 | boost::range_detail::string_, |
| 88 | array_t >::type string_t; |
| 89 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_const_char_ptr_, |
| 90 | boost::range_detail::const_char_ptr_, |
| 91 | string_t >::type const_char_ptr_t; |
| 92 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_char_ptr_, |
| 93 | boost::range_detail::char_ptr_, |
| 94 | const_char_ptr_t >::type char_ptr_t; |
| 95 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_const_wchar_t_ptr_, |
| 96 | boost::range_detail::const_wchar_t_ptr_, |
| 97 | char_ptr_t >::type const_wchar_ptr_t; |
| 98 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_wchar_t_ptr_, |
| 99 | boost::range_detail::wchar_t_ptr_, |
| 100 | const_wchar_ptr_t >::type wchar_ptr_t; |
| 101 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_wchar_t_array_, |
| 102 | boost::range_detail::wchar_t_array_, |
| 103 | wchar_ptr_t >::type wchar_array_t; |
| 104 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_char_array_, |
| 105 | boost::range_detail::char_array_, |
| 106 | wchar_array_t >::type char_array_t; |
| 107 | public: |
| 108 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::is_void<char_array_t>::value, |
| 109 | boost::range_detail::std_container_, |
| 110 | char_array_t >::type type; |
| 111 | }; // class 'range' |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | #endif |
| 116 | |