1#ifndef LIBSBX_UTILITY_STRING_LITERAL_HPP_
2#define LIBSBX_UTILITY_STRING_LITERAL_HPP_
11namespace sbx::utility {
15template<std::forward_iterator InputIterator, std::sentinel_for<InputIterator> Sentinel, std::forward_iterator OutputIterator>
16constexpr auto copy(InputIterator first, Sentinel last, OutputIterator result) -> OutputIterator {
17 while (first != last) {
26template<
typename Character, std::
size_t Size>
31 using character_type = Character;
32 using size_type = std::size_t;
33 using iterator =
const character_type*;
34 using string_view_type = std::basic_string_view<character_type>;
35 using string_type = std::basic_string<character_type>;
37 static constexpr auto npos = std::numeric_limits<size_type>::max();
40 detail::copy(data, data + Size - 1, _data.data());
43 constexpr auto begin()
const noexcept -> iterator {
44 return std::begin(_data);
47 constexpr auto end()
const noexcept -> iterator {
48 return std::end(_data.data());
51 constexpr auto data()
const noexcept ->
const character_type* {
55 constexpr auto size()
const noexcept -> size_type {
59 constexpr auto is_empty()
const noexcept ->
bool {
63 constexpr auto operator[](size_type index)
const noexcept -> character_type {
67 constexpr operator string_view_type()
const noexcept {
68 return string_view_type{_data.data(), Size};
71 constexpr operator string_type()
const noexcept {
72 return (Size != 0u) ? string_type{_data.data(), Size} : std::string{};
75 std::array<character_type, Size - 1> _data;
79template<std::
size_t Size>
82template<std::
size_t Size>
87template<std::
size_t Size>
88struct fmt::formatter<sbx::utility::string_literal<Size>> {
90 template<
typename ParseContext>
91 constexpr auto parse(ParseContext& context) ->
decltype(context.begin()) {
92 return context.begin();
95 template<
typename FormatContext>
97 return fmt::format_to(context.out(),
"{}", std::string{value.data(), value.size()});
Definition: string_literal.hpp:27