3 // Copyright Thorsten Ottosen 2006. 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)
8 // For more information, see http://www.boost.org/libs/range/
11 #ifndef BOOST_RANGE_AS_LITERAL_HPP
12 #define BOOST_RANGE_AS_LITERAL_HPP
18 #ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
19 #include <boost/range/detail/as_literal.hpp>
22 #include <boost/range/iterator_range.hpp>
23 #include <boost/range/detail/str_types.hpp>
25 #include <boost/detail/workaround.hpp>
28 #ifndef BOOST_NO_CWCHAR
34 namespace range_detail
36 inline std::size_t length( const char* s )
41 #ifndef BOOST_NO_CWCHAR
42 inline std::size_t length( const wchar_t* s )
49 // Remark: the compiler cannot choose between T* and T[sz]
50 // overloads, so we must put the T* internal to the
51 // unconstrained version.
54 inline bool is_char_ptr( char* )
59 inline bool is_char_ptr( const char* )
64 #ifndef BOOST_NO_CWCHAR
65 inline bool is_char_ptr( wchar_t* )
70 inline bool is_char_ptr( const wchar_t* )
77 inline long is_char_ptr( const T& /* r */ )
83 inline iterator_range<T*>
84 make_range( T* const r, bool )
86 return iterator_range<T*>( r, r + length(r) );
90 inline iterator_range<BOOST_DEDUCED_TYPENAME range_iterator<T>::type>
91 make_range( T& r, long )
93 return boost::make_iterator_range( r );
98 template< class Range >
99 inline iterator_range<BOOST_DEDUCED_TYPENAME range_iterator<Range>::type>
100 as_literal( Range& r )
102 return range_detail::make_range( r, range_detail::is_char_ptr(r) );
105 template< class Range >
106 inline iterator_range<BOOST_DEDUCED_TYPENAME range_iterator<const Range>::type>
107 as_literal( const Range& r )
109 return range_detail::make_range( r, range_detail::is_char_ptr(r) );
112 template< class Char, std::size_t sz >
113 inline iterator_range<Char*> as_literal( Char (&arr)[sz] )
115 return range_detail::make_range( arr, range_detail::is_char_ptr(arr) );
118 template< class Char, std::size_t sz >
119 inline iterator_range<const Char*> as_literal( const Char (&arr)[sz] )
121 return range_detail::make_range( arr, range_detail::is_char_ptr(arr) );
125 #endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING