Horizon
c_str.hpp
Go to the documentation of this file.
1 // 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 
18 #include <range/v3/range_fwd.hpp>
19 
21 #include <range/v3/utility/static_const.hpp>
24 
25 #include <range/v3/detail/prologue.hpp>
26 
27 namespace 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  {
81  using ch_t = meta::_t<std::remove_cv<Char>>;
82  return ranges::views::delimit(sz, ch_t(0));
83  }
84  };
85 
89  } // namespace views
90 } // namespace ranges
91 
92 #include <range/v3/detail/epilogue.hpp>
93 
94 #endif
RANGES_INLINE_VARIABLE(detail::to_container_fn< detail::from_range< std::vector >>, to_vector) template< template< typename... > class ContT > auto to(RANGES_HIDDEN_DETAIL(detail
For initializing a container of the specified type with the elements of an Range.
Definition: conversion.hpp:399
std::integral_constant< std::size_t, N > size_t
An integral constant wrapper for std::size_t.
Definition: meta.hpp:163
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