1#ifndef LIBSBX_UTILITY_STRING_LITERAL_HPP_
2#define LIBSBX_UTILITY_STRING_LITERAL_HPP_
13namespace sbx::utility {
17template<std::forward_iterator InputIterator, std::sentinel_for<InputIterator> Sentinel, std::forward_iterator OutputIterator>
18constexpr auto copy(InputIterator first, Sentinel last, OutputIterator result) -> OutputIterator {
19 while (first != last) {
28template<
typename Character, std::
size_t Size>
33 using character_type = Character;
34 using size_type = std::size_t;
35 using iterator =
const character_type*;
36 using string_view_type = std::basic_string_view<character_type>;
37 using string_type = std::basic_string<character_type>;
39 static constexpr auto npos = std::numeric_limits<size_type>::max();
42 detail::copy(data, data + Size - 1, _data.data());
45 constexpr auto begin()
const noexcept -> iterator {
46 return std::begin(_data);
49 constexpr auto end()
const noexcept -> iterator {
50 return std::end(_data.data());
53 constexpr auto data()
const noexcept ->
const character_type* {
57 constexpr auto size()
const noexcept -> size_type {
61 constexpr auto is_empty()
const noexcept ->
bool {
65 constexpr auto operator[](size_type index)
const noexcept -> character_type {
69 constexpr auto hash()
const noexcept -> std::size_t {
73 constexpr operator string_view_type()
const noexcept {
74 return string_view_type{_data.data(), Size};
77 constexpr operator string_type()
const noexcept {
78 return (Size != 0u) ? string_type{_data.data(), Size} : std::string{};
81 std::array<character_type, Size - 1> _data;
85template<std::
size_t Size>
88template<std::
size_t Size>
91template<
string_literal String>
92constexpr auto string_id() noexcept -> std::
size_t {
98template<std::
size_t Size>
99struct fmt::formatter<sbx::utility::string_literal<Size>> {
101 template<
typename ParseContext>
102 constexpr auto parse(ParseContext& context) ->
decltype(context.begin()) {
103 return context.begin();
106 template<
typename FormatContext>
108 return fmt::format_to(context.out(),
"{}", std::string{value.data(), value.size()});
113template<
typename Character,
size_t Size>
114struct std::hash<sbx::utility::basic_string_literal<Character, Size>> {
Definition: string_literal.hpp:29
Functor that implements the fnv1a hash algorithm.
Definition: hash.hpp:127