Chris@16
|
1 // Boost.Range library
|
Chris@16
|
2 //
|
Chris@16
|
3 // Copyright Thorsten Ottosen 2006. 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_AS_LITERAL_HPP
|
Chris@16
|
12 #define BOOST_RANGE_AS_LITERAL_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 #ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
Chris@16
|
19 #include <boost/range/detail/as_literal.hpp>
|
Chris@16
|
20 #else
|
Chris@16
|
21
|
Chris@16
|
22 #include <boost/range/iterator_range.hpp>
|
Chris@16
|
23 #include <boost/range/detail/str_types.hpp>
|
Chris@16
|
24
|
Chris@16
|
25 #include <boost/detail/workaround.hpp>
|
Chris@16
|
26
|
Chris@16
|
27 #include <cstring>
|
Chris@16
|
28 #ifndef BOOST_NO_CWCHAR
|
Chris@16
|
29 #include <cwchar>
|
Chris@16
|
30 #endif
|
Chris@16
|
31
|
Chris@16
|
32 namespace boost
|
Chris@16
|
33 {
|
Chris@16
|
34 namespace range_detail
|
Chris@16
|
35 {
|
Chris@16
|
36 inline std::size_t length( const char* s )
|
Chris@16
|
37 {
|
Chris@16
|
38 return strlen( s );
|
Chris@16
|
39 }
|
Chris@16
|
40
|
Chris@16
|
41 #ifndef BOOST_NO_CWCHAR
|
Chris@16
|
42 inline std::size_t length( const wchar_t* s )
|
Chris@16
|
43 {
|
Chris@16
|
44 return wcslen( s );
|
Chris@16
|
45 }
|
Chris@16
|
46 #endif
|
Chris@16
|
47
|
Chris@16
|
48 //
|
Chris@16
|
49 // Remark: the compiler cannot choose between T* and T[sz]
|
Chris@16
|
50 // overloads, so we must put the T* internal to the
|
Chris@16
|
51 // unconstrained version.
|
Chris@16
|
52 //
|
Chris@16
|
53
|
Chris@16
|
54 inline bool is_char_ptr( char* )
|
Chris@16
|
55 {
|
Chris@16
|
56 return true;
|
Chris@16
|
57 }
|
Chris@16
|
58
|
Chris@16
|
59 inline bool is_char_ptr( const char* )
|
Chris@16
|
60 {
|
Chris@16
|
61 return true;
|
Chris@16
|
62 }
|
Chris@16
|
63
|
Chris@16
|
64 #ifndef BOOST_NO_CWCHAR
|
Chris@16
|
65 inline bool is_char_ptr( wchar_t* )
|
Chris@16
|
66 {
|
Chris@16
|
67 return true;
|
Chris@16
|
68 }
|
Chris@16
|
69
|
Chris@16
|
70 inline bool is_char_ptr( const wchar_t* )
|
Chris@16
|
71 {
|
Chris@16
|
72 return true;
|
Chris@16
|
73 }
|
Chris@16
|
74 #endif
|
Chris@16
|
75
|
Chris@16
|
76 template< class T >
|
Chris@16
|
77 inline long is_char_ptr( const T& /* r */ )
|
Chris@16
|
78 {
|
Chris@16
|
79 return 0L;
|
Chris@16
|
80 }
|
Chris@16
|
81
|
Chris@16
|
82 template< class T >
|
Chris@16
|
83 inline iterator_range<T*>
|
Chris@16
|
84 make_range( T* const r, bool )
|
Chris@16
|
85 {
|
Chris@16
|
86 return iterator_range<T*>( r, r + length(r) );
|
Chris@16
|
87 }
|
Chris@16
|
88
|
Chris@16
|
89 template< class T >
|
Chris@16
|
90 inline iterator_range<BOOST_DEDUCED_TYPENAME range_iterator<T>::type>
|
Chris@16
|
91 make_range( T& r, long )
|
Chris@16
|
92 {
|
Chris@16
|
93 return boost::make_iterator_range( r );
|
Chris@16
|
94 }
|
Chris@16
|
95
|
Chris@16
|
96 }
|
Chris@16
|
97
|
Chris@16
|
98 template< class Range >
|
Chris@16
|
99 inline iterator_range<BOOST_DEDUCED_TYPENAME range_iterator<Range>::type>
|
Chris@16
|
100 as_literal( Range& r )
|
Chris@16
|
101 {
|
Chris@16
|
102 return range_detail::make_range( r, range_detail::is_char_ptr(r) );
|
Chris@16
|
103 }
|
Chris@16
|
104
|
Chris@16
|
105 template< class Range >
|
Chris@16
|
106 inline iterator_range<BOOST_DEDUCED_TYPENAME range_iterator<const Range>::type>
|
Chris@16
|
107 as_literal( const Range& r )
|
Chris@16
|
108 {
|
Chris@16
|
109 return range_detail::make_range( r, range_detail::is_char_ptr(r) );
|
Chris@16
|
110 }
|
Chris@16
|
111
|
Chris@16
|
112 template< class Char, std::size_t sz >
|
Chris@16
|
113 inline iterator_range<Char*> as_literal( Char (&arr)[sz] )
|
Chris@16
|
114 {
|
Chris@16
|
115 return range_detail::make_range( arr, range_detail::is_char_ptr(arr) );
|
Chris@16
|
116 }
|
Chris@16
|
117
|
Chris@16
|
118 template< class Char, std::size_t sz >
|
Chris@16
|
119 inline iterator_range<const Char*> as_literal( const Char (&arr)[sz] )
|
Chris@16
|
120 {
|
Chris@16
|
121 return range_detail::make_range( arr, range_detail::is_char_ptr(arr) );
|
Chris@16
|
122 }
|
Chris@16
|
123 }
|
Chris@16
|
124
|
Chris@16
|
125 #endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
Chris@16
|
126
|
Chris@16
|
127 #endif
|