cpp-stat-bench 0.24.0
Benchmark library with statistics for C++.
Loading...
Searching...
No Matches
benchmark_group_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 {
33
38public:
44 explicit BenchmarkGroupName(util::Utf8String str) noexcept;
45
51 explicit BenchmarkGroupName(std::string str)
52 : BenchmarkGroupName(util::Utf8String(std::move(str))) {}
53
59 [[nodiscard]] auto str() const noexcept -> const util::Utf8String&;
60
61private:
63 util::Utf8String str_;
64};
65
74[[nodiscard]] inline auto operator==(const BenchmarkGroupName& lhs,
75 const BenchmarkGroupName& rhs) noexcept -> bool {
76 return lhs.str() == rhs.str();
77}
78
87[[nodiscard]] inline auto operator!=(const BenchmarkGroupName& lhs,
88 const BenchmarkGroupName& rhs) noexcept -> bool {
89 return !(lhs == rhs);
90}
91
92} // namespace stat_bench
93
94namespace fmt {
95
99template <>
100struct formatter<stat_bench::BenchmarkGroupName>
101 : public formatter<stat_bench::util::Utf8String> {
110 fmt::format_context& context) const -> fmt::format_context::iterator {
111 return formatter<stat_bench::util::Utf8String>::format(
112 val.str(), context);
113 }
114};
115
116} // namespace fmt
117
118namespace stat_bench {
119
127inline auto operator<<(std::ostream& stream, const BenchmarkGroupName& val)
128 -> std::ostream& {
129 return stream << val.str();
130}
131
132} // namespace stat_bench
133
134namespace std {
135
139template <>
140class hash<stat_bench::BenchmarkGroupName> {
141public:
149 -> std::size_t {
150 return hash_(val.str());
151 }
152
153private:
155 std::hash<stat_bench::util::Utf8String> hash_;
156};
157
158} // namespace std
Class of names of groups of benchmarks.
BenchmarkGroupName(util::Utf8String str) noexcept
Constructor.
auto str() const noexcept -> const util::Utf8String &
Get the string of the name.
BenchmarkGroupName(std::string str)
Constructor.
Class of UTF-8 encoded string.
Definition utf8_string.h:35
auto operator()(const stat_bench::BenchmarkGroupName &val) const -> std::size_t
Hash function.
Namespace of utility functions and classes.
Namespace of stat_bench source codes.
auto operator!=(const BenchmarkCaseName &lhs, const BenchmarkCaseName &rhs) noexcept -> bool
Compare two BenchmarkCaseName objects.
auto operator<<(std::ostream &stream, const BenchmarkCaseName &val) -> std::ostream &
Format to a stream.
STL namespace.
auto format(const stat_bench::BenchmarkGroupName &val, fmt::format_context &context) const -> fmt::format_context::iterator
Format.
Definition of Utf8String class.