/// \file // Range v3 library // // Copyright Eric Niebler 2014-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_VIEW_C_STR_HPP #define RANGES_V3_VIEW_C_STR_HPP #include #include #include #include #include #include namespace ranges { /// \cond namespace detail { template struct is_char_type_ : std::false_type {}; template<> struct is_char_type_ : std::true_type {}; template<> struct is_char_type_ : std::true_type {}; template<> struct is_char_type_ : std::true_type {}; template<> struct is_char_type_ : std::true_type {}; template using is_char_type = is_char_type_>>; } // namespace detail /// \endcond /// \addtogroup group-views /// @{ namespace views { /// View a `\0`-terminated C string (e.g. from a const char*) as a /// range. struct c_str_fn { // Fixed-length template auto operator()(Char (&sz)[N]) const -> CPP_ret(ranges::subrange)( // requires detail::is_char_type::value) { return {&sz[0], &sz[N - 1]}; } // Null-terminated template auto operator()(Char * sz) const volatile -> CPP_ret(ranges::delimit_view< ranges::subrange, meta::_t>>)( // requires detail::is_char_type::value) { using ch_t = meta::_t>; return ranges::views::delimit(sz, ch_t(0)); } }; /// \relates c_str_fn /// \ingroup group-views RANGES_INLINE_VARIABLE(c_str_fn, c_str) } // namespace views } // namespace ranges #endif