cpp-stat-bench 0.24.0
Benchmark library with statistics for C++.
Loading...
Searching...
No Matches
parameter_name.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#include <utility>
27
28#include <fmt/base.h>
29
31
32namespace stat_bench {
33namespace param {
34
39public:
45 explicit ParameterName(util::Utf8String str) noexcept;
46
52 explicit ParameterName(std::string str)
53 : ParameterName(util::Utf8String(std::move(str))) {}
54
60 [[nodiscard]] auto str() const noexcept -> const util::Utf8String&;
61
62private:
64 util::Utf8String str_;
65};
66
75[[nodiscard]] inline auto operator==(
76 const ParameterName& lhs, const ParameterName& rhs) noexcept -> bool {
77 return lhs.str() == rhs.str();
78}
79
88[[nodiscard]] inline auto operator!=(
89 const ParameterName& lhs, const ParameterName& rhs) noexcept -> bool {
90 return !(lhs == rhs);
91}
92
103[[nodiscard]] inline auto operator<(
104 const ParameterName& lhs, const ParameterName& rhs) noexcept -> bool {
105 return lhs.str() < rhs.str();
106}
107
118[[nodiscard]] inline auto operator>(
119 const ParameterName& lhs, const ParameterName& rhs) noexcept -> bool {
120 return rhs < lhs;
121}
122
133[[nodiscard]] inline auto operator<=(
134 const ParameterName& lhs, const ParameterName& rhs) noexcept -> bool {
135 return !(rhs < lhs);
136}
137
148[[nodiscard]] inline auto operator>=(
149 const ParameterName& lhs, const ParameterName& rhs) noexcept -> bool {
150 return !(lhs < rhs);
151}
152
153} // namespace param
154} // namespace stat_bench
155
156namespace fmt {
157
161template <>
162struct formatter<stat_bench::param::ParameterName>
163 : public formatter<stat_bench::util::Utf8String> {
172 fmt::format_context& context) const -> fmt::format_context::iterator {
173 return formatter<stat_bench::util::Utf8String>::format(
174 val.str(), context);
175 }
176};
177
178} // namespace fmt
179
180namespace stat_bench {
181namespace param {
182
190inline auto operator<<(std::ostream& stream, const ParameterName& val)
191 -> std::ostream& {
192 return stream << val.str();
193}
194
195} // namespace param
196} // namespace stat_bench
197
198namespace std {
199
203template <>
204class hash<stat_bench::param::ParameterName> {
205public:
213 -> std::size_t {
214 return hash_(val.str());
215 }
216
217private:
219 std::hash<stat_bench::util::Utf8String> hash_;
220};
221
222} // namespace std
Class of names of parameters.
ParameterName(std::string str)
Constructor.
auto str() const noexcept -> const util::Utf8String &
Get the string of the name.
ParameterName(util::Utf8String str) noexcept
Constructor.
Class of UTF-8 encoded string.
Definition utf8_string.h:35
auto operator()(const stat_bench::param::ParameterName &val) const -> std::size_t
Hash function.
Namespace of parameters of benchmarks.
auto operator<=(const ParameterName &lhs, const ParameterName &rhs) noexcept -> bool
Compare two ParameterName objects.
auto operator<(const ParameterName &lhs, const ParameterName &rhs) noexcept -> bool
Compare two ParameterName objects.
auto operator<<(std::ostream &stream, const ParameterName &val) -> std::ostream &
Format to a stream.
auto operator!=(const ParameterName &lhs, const ParameterName &rhs) noexcept -> bool
Compare two ParameterName objects.
auto operator>(const ParameterName &lhs, const ParameterName &rhs) noexcept -> bool
Compare two ParameterName objects.
auto operator>=(const ParameterName &lhs, const ParameterName &rhs) noexcept -> bool
Compare two ParameterName objects.
Namespace of utility functions and classes.
Namespace of stat_bench source codes.
STL namespace.
auto format(const stat_bench::param::ParameterName &val, fmt::format_context &context) const -> fmt::format_context::iterator
Format.
Definition of Utf8String class.