cpp-stat-bench 0.24.0
Benchmark library with statistics for C++.
Loading...
Searching...
No Matches
utf8_string.h
Go to the documentation of this file.
1/*
2 * Copyright 2024 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#pragma once
21
22#include <cstddef>
23#include <functional>
24#include <ostream>
25#include <string>
26
27#include <fmt/base.h>
28
29namespace stat_bench {
30namespace util {
31
36public:
42 explicit Utf8String(std::string str);
43
47 Utf8String() = default;
48
54 [[nodiscard]] auto str() const noexcept -> const std::string&;
55
56private:
58 std::string str_;
59};
60
69[[nodiscard]] auto operator==(
70 const Utf8String& lhs, const Utf8String& rhs) noexcept -> bool;
71
80[[nodiscard]] auto operator!=(
81 const Utf8String& lhs, const Utf8String& rhs) noexcept -> bool;
82
93[[nodiscard]] auto operator<(
94 const Utf8String& lhs, const Utf8String& rhs) noexcept -> bool;
95
106[[nodiscard]] auto operator>(
107 const Utf8String& lhs, const Utf8String& rhs) noexcept -> bool;
108
119[[nodiscard]] auto operator<=(
120 const Utf8String& lhs, const Utf8String& rhs) noexcept -> bool;
121
132[[nodiscard]] auto operator>=(
133 const Utf8String& lhs, const Utf8String& rhs) noexcept -> bool;
134
135} // namespace util
136} // namespace stat_bench
137
138namespace fmt {
139
144template <>
145struct formatter<stat_bench::util::Utf8String> : public formatter<string_view> {
153 auto format(const stat_bench::util::Utf8String& val,
154 format_context& context) const -> format_context::iterator;
155};
156
157} // namespace fmt
158
159namespace stat_bench {
160namespace util {
161
169auto operator<<(std::ostream& stream, const Utf8String& val) -> std::ostream&;
170
171} // namespace util
172} // namespace stat_bench
173
174namespace std {
175
179template <>
180class hash<stat_bench::util::Utf8String> {
181public:
189 -> std::size_t {
190 return hash_(val.str());
191 }
192
193private:
195 std::hash<std::string> hash_;
196};
197
198} // namespace std
Class of UTF-8 encoded string.
Definition utf8_string.h:35
Utf8String(std::string str)
Constructor.
auto str() const noexcept -> const std::string &
Get the string.
Utf8String()=default
Constructor. (Empty string.)
auto operator()(const stat_bench::util::Utf8String &val) const -> std::size_t
Hash function.
Namespace of fmt library.
Namespace of utility functions and classes.
auto operator<<(std::ostream &stream, const Utf8String &val) -> std::ostream &
Format to a stream.
Namespace of stat_bench source codes.
STL namespace.
auto format(const stat_bench::util::Utf8String &val, format_context &context) const -> format_context::iterator
Format.