// Copyright (C) 2020 T. Zachary Laine // // Distributed under 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) #ifndef BOOST_PARSER_DETAIL_TEXT_CONCEPTS_HPP #define BOOST_PARSER_DETAIL_TEXT_CONCEPTS_HPP #include #include #include #if BOOST_PARSER_DETAIL_TEXT_USE_CONCEPTS #include #include namespace boost::parser::detail { namespace text { BOOST_PARSER_DETAIL_TEXT_NAMESPACE_V2 { //[ concepts_concepts #ifdef _MSC_VER inline constexpr format wchar_t_format = format::utf16; #else inline constexpr format wchar_t_format = format::utf32; #endif template concept code_unit = (std::same_as && F == format::utf8) || (std::same_as && F == format::utf16) || (std::same_as && F == format::utf32) || (std::same_as && F == format::utf8) || (std::same_as && F == wchar_t_format); template concept utf8_code_unit = code_unit; template concept utf16_code_unit = code_unit; template concept utf32_code_unit = code_unit; template concept code_unit_iter = std::input_iterator && code_unit, F>; template concept utf_code_unit = utf8_code_unit || utf16_code_unit || utf32_code_unit; template concept code_unit_range = std::ranges::input_range && code_unit, F>; template concept contiguous_code_unit_range = std::ranges::contiguous_range && code_unit, F>; template concept utf8_iter = code_unit_iter; template concept utf8_range = code_unit_range; template concept contiguous_utf8_range = contiguous_code_unit_range; template concept utf16_iter = code_unit_iter; template concept utf16_range = code_unit_range; template concept contiguous_utf16_range = contiguous_code_unit_range; template concept utf32_iter = code_unit_iter; template concept utf32_range = code_unit_range; template concept contiguous_utf32_range = contiguous_code_unit_range; template concept code_point = utf32_code_unit; template concept code_point_iter = utf32_iter; template concept code_point_range = utf32_range; template concept utf_iter = utf8_iter || utf16_iter || utf32_iter; template concept utf_range = utf8_range || utf16_range || utf32_range; template concept grapheme_iter = std::input_iterator && code_point_range> && requires(T t) { { t.base() } -> code_point_iter; }; template concept grapheme_range = std::ranges::input_range && grapheme_iter>; template using code_point_iterator_t = decltype(std::declval().begin().base()); template using code_point_sentinel_t = decltype(std::declval().end().base()); template concept grapheme_iter_code_unit = grapheme_iter && requires(T t) { { t.base().base() } -> code_unit_iter; }; template concept grapheme_range_code_unit = grapheme_range && grapheme_iter_code_unit, F>; namespace dtl { template concept eraseable_insertable_sized_bidi_range = std::ranges::sized_range && std::ranges::input_range && requires(T t, CodeUnit const * it) { { t.erase(t.begin(), t.end()) } -> std::same_as>; { t.insert(t.end(), it, it) } -> std::same_as>; }; } template concept utf8_string = utf8_code_unit> && dtl::eraseable_insertable_sized_bidi_range< T, std::ranges::range_value_t>; template concept utf16_string = utf16_code_unit> && dtl::eraseable_insertable_sized_bidi_range< T, std::ranges::range_value_t>; template concept utf_string = utf8_string || utf16_string; template concept transcoding_error_handler = requires(T t, std::string_view msg) { { t(msg) } -> std::same_as; }; //] // Clang 13 defines __cpp_lib_concepts but not std::indirectly copyable. #if defined(__clang_major__) && __clang_major__ <= 13 template concept indirectly_copyable = std::indirectly_readable && std::indirectly_writable>; #else template concept indirectly_copyable = std::indirectly_copyable; #endif } }} #endif namespace boost::parser::detail { namespace text { namespace detail { #if BOOST_PARSER_DETAIL_TEXT_USE_CONCEPTS template using iterator_t = std::ranges::iterator_t; template using sentinel_t = std::ranges::sentinel_t; template using iter_value_t = std::iter_value_t; template using iter_reference_t = std::iter_reference_t; template using range_value_t = std::ranges::range_value_t; template using range_reference_t = std::ranges::range_reference_t; template using range_difference_t = std::ranges::range_difference_t; #else template using iterator_t = decltype(detail::begin(std::declval())); template using sentinel_t = decltype(detail::end(std::declval())); template using iter_value_t = typename std::iterator_traits::value_type; template using iter_reference_t = decltype(*std::declval()); template using range_value_t = iter_value_t>; template using range_reference_t = iter_reference_t>; template using range_difference_t = std::ptrdiff_t; template constexpr bool code_unit_v = #if defined(__cpp_char8_t) std::is_same_v || #endif std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v; #endif }}} #endif