]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/range/as_literal.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / range / as_literal.hpp
CommitLineData
7c673cae
FG
1// Boost.Range library
2//
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)
7//
8// For more information, see http://www.boost.org/libs/range/
9//
10
11#ifndef BOOST_RANGE_AS_LITERAL_HPP
12#define BOOST_RANGE_AS_LITERAL_HPP
13
14#if defined(_MSC_VER)
15# pragma once
16#endif
17
18#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
19#include <boost/range/detail/as_literal.hpp>
20#else
21
22#include <boost/range/iterator_range.hpp>
23#include <boost/range/detail/str_types.hpp>
24
25#include <boost/detail/workaround.hpp>
26
27#include <cstring>
92f5a8d4
TL
28
29#if !defined(BOOST_NO_CXX11_CHAR16_T) || !defined(BOOST_NO_CXX11_CHAR32_T)
30#include <string> // for std::char_traits
31#endif
32
7c673cae
FG
33#ifndef BOOST_NO_CWCHAR
34#include <cwchar>
35#endif
36
37namespace boost
38{
39 namespace range_detail
40 {
41 inline std::size_t length( const char* s )
42 {
43 return strlen( s );
44 }
45
92f5a8d4
TL
46#ifndef BOOST_NO_CXX11_CHAR16_T
47 inline std::size_t length( const char16_t* s )
48 {
49 return std::char_traits<char16_t>::length( s );
50 }
51#endif
52
53#ifndef BOOST_NO_CXX11_CHAR32_T
54 inline std::size_t length( const char32_t* s )
55 {
56 return std::char_traits<char32_t>::length( s );
57 }
58#endif
59
7c673cae
FG
60#ifndef BOOST_NO_CWCHAR
61 inline std::size_t length( const wchar_t* s )
62 {
63 return wcslen( s );
64 }
65#endif
66
67 //
68 // Remark: the compiler cannot choose between T* and T[sz]
69 // overloads, so we must put the T* internal to the
70 // unconstrained version.
71 //
72
73 inline bool is_char_ptr( char* )
74 {
75 return true;
76 }
77
78 inline bool is_char_ptr( const char* )
79 {
80 return true;
81 }
82
92f5a8d4
TL
83#ifndef BOOST_NO_CXX11_CHAR16_T
84 inline bool is_char_ptr( char16_t* )
85 {
86 return true;
87 }
88
89 inline bool is_char_ptr( const char16_t* )
90 {
91 return true;
92 }
93#endif
94
95#ifndef BOOST_NO_CXX11_CHAR32_T
96 inline bool is_char_ptr( char32_t* )
97 {
98 return true;
99 }
100
101 inline bool is_char_ptr( const char32_t* )
102 {
103 return true;
104 }
105#endif
106
7c673cae
FG
107#ifndef BOOST_NO_CWCHAR
108 inline bool is_char_ptr( wchar_t* )
109 {
110 return true;
111 }
112
113 inline bool is_char_ptr( const wchar_t* )
114 {
115 return true;
116 }
117#endif
118
119 template< class T >
120 inline long is_char_ptr( const T& /* r */ )
121 {
122 return 0L;
123 }
124
125 template< class T >
126 inline iterator_range<T*>
127 make_range( T* const r, bool )
128 {
129 return iterator_range<T*>( r, r + length(r) );
130 }
131
132 template< class T >
133 inline iterator_range<BOOST_DEDUCED_TYPENAME range_iterator<T>::type>
134 make_range( T& r, long )
135 {
136 return boost::make_iterator_range( r );
137 }
138
139 }
140
141 template< class Range >
142 inline iterator_range<BOOST_DEDUCED_TYPENAME range_iterator<Range>::type>
143 as_literal( Range& r )
144 {
145 return range_detail::make_range( r, range_detail::is_char_ptr(r) );
146 }
147
148 template< class Range >
149 inline iterator_range<BOOST_DEDUCED_TYPENAME range_iterator<const Range>::type>
150 as_literal( const Range& r )
151 {
152 return range_detail::make_range( r, range_detail::is_char_ptr(r) );
153 }
154
155 template< class Char, std::size_t sz >
156 inline iterator_range<Char*> as_literal( Char (&arr)[sz] )
157 {
158 return range_detail::make_range( arr, range_detail::is_char_ptr(arr) );
159 }
160
161 template< class Char, std::size_t sz >
162 inline iterator_range<const Char*> as_literal( const Char (&arr)[sz] )
163 {
164 return range_detail::make_range( arr, range_detail::is_char_ptr(arr) );
165 }
166}
167
168#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
169
170#endif