2#ifndef LIBSBX_UTILITY_STRING_LITERAL_HPP_
3#define LIBSBX_UTILITY_STRING_LITERAL_HPP_
10#include <fmt/format.h>
14namespace sbx::utility {
18template<std::forward_iterator InputIterator, std::sentinel_for<InputIterator> Sentinel, std::forward_iterator OutputIterator>
19constexpr auto copy(InputIterator first, Sentinel last, OutputIterator result) -> OutputIterator {
20 while (first != last) {
29template<
typename Character, std::
size_t Size>
34 using character_type = Character;
35 using size_type = std::size_t;
36 using iterator =
const character_type*;
37 using string_view_type = std::basic_string_view<character_type>;
38 using string_type = std::basic_string<character_type>;
40 static constexpr auto npos = std::numeric_limits<size_type>::max();
43 detail::copy(data, data + Size - 1, _data.data());
46 constexpr auto begin()
const noexcept -> iterator {
47 return std::begin(_data);
50 constexpr auto end()
const noexcept -> iterator {
51 return std::end(_data.data());
54 constexpr auto data()
const noexcept ->
const character_type* {
58 constexpr auto size()
const noexcept -> size_type {
62 constexpr auto is_empty()
const noexcept ->
bool {
66 constexpr auto operator[](
const size_type index)
const noexcept -> character_type {
70 constexpr auto at(
const size_type index)
const noexcept -> character_type {
71 return _data.at(index);
74 constexpr auto hash()
const noexcept -> std::size_t {
78 constexpr operator string_view_type()
const noexcept {
79 return string_view_type{_data.data(), Size};
82 constexpr operator string_type()
const noexcept {
83 return (Size != 0u) ? string_type{_data.data(), Size} : std::string{};
86 std::array<character_type, Size - 1> _data;
90template<std::
size_t Size>
93template<std::
size_t Size>
96template<
string_literal String>
97constexpr auto string_id() noexcept -> std::
size_t {
103template<std::
size_t Size>
104struct fmt::formatter<sbx::utility::string_literal<Size>> {
106 template<
typename ParseContext>
107 constexpr auto parse(ParseContext& context) ->
decltype(context.begin()) {
108 return context.begin();
111 template<
typename FormatContext>
113 return fmt::format_to(context.out(),
"{}", std::string{value.data(), value.size()});
118template<
typename Character,
size_t Size>
119struct std::hash<sbx::utility::basic_string_literal<Character, Size>> {
Definition: string_literal.hpp:30
Functor that implements the fnv1a hash algorithm.
Definition: hash.hpp:128