Horizon
Loading...
Searching...
No Matches
c_str.hpp
Go to the documentation of this file.
1
2// Range v3 library
3//
4// Copyright Eric Niebler 2014-present
5//
6// Use, modification and distribution is subject to the
7// Boost Software License, Version 1.0. (See accompanying
8// file LICENSE_1_0.txt or copy at
9// http://www.boost.org/LICENSE_1_0.txt)
10//
11// Project home: https://github.com/ericniebler/range-v3
12//
13#ifndef RANGES_V3_VIEW_C_STR_HPP
14#define RANGES_V3_VIEW_C_STR_HPP
15
16#include <type_traits>
17
19
21#include <range/v3/utility/static_const.hpp>
24
25#include <range/v3/detail/prologue.hpp>
26
27namespace ranges
28{
30 namespace detail
31 {
32 template<typename T>
33 struct is_char_type_ : std::false_type
34 {};
35
36 template<>
37 struct is_char_type_<char> : std::true_type
38 {};
39
40 template<>
41 struct is_char_type_<wchar_t> : std::true_type
42 {};
43
44 template<>
45 struct is_char_type_<char16_t> : std::true_type
46 {};
47
48 template<>
49 struct is_char_type_<char32_t> : std::true_type
50 {};
51
52 template<typename T>
53 using is_char_type = is_char_type_<meta::_t<std::remove_cv<T>>>;
54 } // namespace detail
56
59 namespace views
60 {
63 struct c_str_fn
64 {
65 // Fixed-length
66 template(typename Char, std::size_t N)(
67 requires detail::is_char_type<Char>::value) //
68 ranges::subrange<Char *> operator()(Char (&sz)[N]) const
69 {
70 return {&sz[0], &sz[N - 1]};
71 }
72
73 // Null-terminated
74 template(typename Char)(
75 requires detail::is_char_type<Char>::value) //
79 operator()(Char * sz) const volatile
80 {
82 return ranges::views::delimit(sz, ch_t(0));
83 }
84 };
85
88 RANGES_INLINE_VARIABLE(c_str_fn, c_str)
89 } // namespace views
90} // namespace ranges
91
92#include <range/v3/detail/epilogue.hpp>
93
94#endif
typename T::type _t
Type alias for T::type.
Definition meta.hpp:141
Definition delimit.hpp:41
Definition subrange.hpp:196
View a \0-terminated C string (e.g.
Definition c_str.hpp:64