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