Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:09:54

0001 /// \file
0002 // Range v3 library
0003 //
0004 //  Copyright Eric Niebler 2014-present
0005 //
0006 //  Use, modification and distribution is subject to the
0007 //  Boost Software License, Version 1.0. (See accompanying
0008 //  file LICENSE_1_0.txt or copy at
0009 //  http://www.boost.org/LICENSE_1_0.txt)
0010 //
0011 // Project home: https://github.com/ericniebler/range-v3
0012 //
0013 #ifndef RANGES_V3_VIEW_C_STR_HPP
0014 #define RANGES_V3_VIEW_C_STR_HPP
0015 
0016 #include <type_traits>
0017 
0018 #include <range/v3/range_fwd.hpp>
0019 
0020 #include <range/v3/iterator/unreachable_sentinel.hpp>
0021 #include <range/v3/utility/static_const.hpp>
0022 #include <range/v3/view/delimit.hpp>
0023 #include <range/v3/view/subrange.hpp>
0024 
0025 #include <range/v3/detail/prologue.hpp>
0026 
0027 namespace ranges
0028 {
0029     /// \cond
0030     namespace detail
0031     {
0032         template<typename T>
0033         struct is_char_type_ : std::false_type
0034         {};
0035 
0036         template<>
0037         struct is_char_type_<char> : std::true_type
0038         {};
0039 
0040         template<>
0041         struct is_char_type_<wchar_t> : std::true_type
0042         {};
0043 
0044         template<>
0045         struct is_char_type_<char16_t> : std::true_type
0046         {};
0047 
0048         template<>
0049         struct is_char_type_<char32_t> : std::true_type
0050         {};
0051 
0052         template<typename T>
0053         using is_char_type = is_char_type_<meta::_t<std::remove_cv<T>>>;
0054     } // namespace detail
0055     /// \endcond
0056 
0057     /// \addtogroup group-views
0058     /// @{
0059     namespace views
0060     {
0061         /// View a `\0`-terminated C string (e.g. from a const char*) as a
0062         /// range.
0063         struct c_str_fn
0064         {
0065             // Fixed-length
0066             template(typename Char, std::size_t N)(
0067                 requires detail::is_char_type<Char>::value) //
0068             ranges::subrange<Char *> operator()(Char (&sz)[N]) const
0069             {
0070                 return {&sz[0], &sz[N - 1]};
0071             }
0072 
0073             // Null-terminated
0074             template(typename Char)(
0075                 requires detail::is_char_type<Char>::value) //
0076             ranges::delimit_view<
0077                 ranges::subrange<Char *, ranges::unreachable_sentinel_t>,
0078                 meta::_t<std::remove_cv<Char>>> //
0079             operator()(Char * sz) const volatile
0080             {
0081                 using ch_t = meta::_t<std::remove_cv<Char>>;
0082                 return ranges::views::delimit(sz, ch_t(0));
0083             }
0084         };
0085 
0086         /// \relates c_str_fn
0087         /// \ingroup group-views
0088         RANGES_INLINE_VARIABLE(c_str_fn, c_str)
0089     } // namespace views
0090 } // namespace ranges
0091 
0092 #include <range/v3/detail/epilogue.hpp>
0093 
0094 #endif