blob: 997ed2e55785f698596cb280b96df735fe079a28 [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// 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
Jeff Thompson3d613fd2013-10-15 15:39:04 -070011#ifndef NDNBOOST_RANGE_AS_LITERAL_HPP
12#define NDNBOOST_RANGE_AS_LITERAL_HPP
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070013
14#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15# pragma once
16#endif
17
Jeff Thompson3d613fd2013-10-15 15:39:04 -070018#ifdef NDNBOOST_NO_FUNCTION_TEMPLATE_ORDERING
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070019#include <ndnboost/range/detail/as_literal.hpp>
20#else
21
22#include <ndnboost/range/iterator_range.hpp>
23#include <ndnboost/range/detail/str_types.hpp>
24
25#include <ndnboost/detail/workaround.hpp>
26
27#include <cstring>
Jeff Thompson3d613fd2013-10-15 15:39:04 -070028#ifndef NDNBOOST_NO_CWCHAR
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070029#include <cwchar>
30#endif
31
32namespace ndnboost
33{
34 namespace range_detail
35 {
36 inline std::size_t length( const char* s )
37 {
38 return strlen( s );
39 }
40
Jeff Thompson3d613fd2013-10-15 15:39:04 -070041#ifndef NDNBOOST_NO_CWCHAR
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070042 inline std::size_t length( const wchar_t* s )
43 {
44 return wcslen( s );
45 }
46#endif
47
48 //
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.
52 //
53
54 inline bool is_char_ptr( char* )
55 {
56 return true;
57 }
58
59 inline bool is_char_ptr( const char* )
60 {
61 return true;
62 }
63
Jeff Thompson3d613fd2013-10-15 15:39:04 -070064#ifndef NDNBOOST_NO_CWCHAR
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070065 inline bool is_char_ptr( wchar_t* )
66 {
67 return true;
68 }
69
70 inline bool is_char_ptr( const wchar_t* )
71 {
72 return true;
73 }
74#endif
75
76 template< class T >
77 inline long is_char_ptr( const T& /* r */ )
78 {
79 return 0L;
80 }
81
82 template< class T >
83 inline iterator_range<T*>
84 make_range( T* const r, bool )
85 {
86 return iterator_range<T*>( r, r + length(r) );
87 }
88
89 template< class T >
Jeff Thompson3d613fd2013-10-15 15:39:04 -070090 inline iterator_range<NDNBOOST_DEDUCED_TYPENAME range_iterator<T>::type>
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070091 make_range( T& r, long )
92 {
93 return ndnboost::make_iterator_range( r );
94 }
95
96 }
97
98 template< class Range >
Jeff Thompson3d613fd2013-10-15 15:39:04 -070099 inline iterator_range<NDNBOOST_DEDUCED_TYPENAME range_iterator<Range>::type>
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700100 as_literal( Range& r )
101 {
102 return range_detail::make_range( r, range_detail::is_char_ptr(r) );
103 }
104
105 template< class Range >
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700106 inline iterator_range<NDNBOOST_DEDUCED_TYPENAME range_iterator<const Range>::type>
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700107 as_literal( const Range& r )
108 {
109 return range_detail::make_range( r, range_detail::is_char_ptr(r) );
110 }
111
112 template< class Char, std::size_t sz >
113 inline iterator_range<Char*> as_literal( Char (&arr)[sz] )
114 {
115 return range_detail::make_range( arr, range_detail::is_char_ptr(arr) );
116 }
117
118 template< class Char, std::size_t sz >
119 inline iterator_range<const Char*> as_literal( const Char (&arr)[sz] )
120 {
121 return range_detail::make_range( arr, range_detail::is_char_ptr(arr) );
122 }
123}
124
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700125#endif // NDNBOOST_NO_FUNCTION_TEMPLATE_ORDERING
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700126
127#endif