cpp-stat-bench 0.24.0
Benchmark library with statistics for C++.
Loading...
Searching...
No Matches
measurer_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 <ostream>
23#include <string>
24#include <utility>
25
26#include <fmt/base.h>
27
29
30namespace stat_bench {
31namespace measurer {
32
37public:
43 explicit MeasurerName(util::Utf8String str) noexcept;
44
50 explicit MeasurerName(std::string str)
51 : MeasurerName(util::Utf8String(std::move(str))) {}
52
58 [[nodiscard]] auto str() const noexcept -> const util::Utf8String&;
59
60private:
62 util::Utf8String str_;
63};
64
73[[nodiscard]] inline auto operator==(
74 const MeasurerName& lhs, const MeasurerName& rhs) noexcept -> bool {
75 return lhs.str() == rhs.str();
76}
77
86[[nodiscard]] inline auto operator!=(
87 const MeasurerName& lhs, const MeasurerName& rhs) noexcept -> bool {
88 return !(lhs == rhs);
89}
90
91} // namespace measurer
92} // namespace stat_bench
93
94namespace fmt {
95
100template <>
101struct formatter<stat_bench::measurer::MeasurerName>
102 : public formatter<stat_bench::util::Utf8String> {
111 fmt::format_context& context) const -> fmt::format_context::iterator {
112 return formatter<stat_bench::util::Utf8String>::format(
113 val.str(), context);
114 }
115};
116
117} // namespace fmt
118
119namespace stat_bench {
120namespace measurer {
121
129inline auto operator<<(std::ostream& stream, const MeasurerName& val)
130 -> std::ostream& {
131 return stream << val.str();
132}
133
134} // namespace measurer
135} // namespace stat_bench
Class of names of measurers.
auto str() const noexcept -> const util::Utf8String &
Get the string of the name.
MeasurerName(util::Utf8String str) noexcept
Constructor.
MeasurerName(std::string str)
Constructor.
Class of UTF-8 encoded string.
Definition utf8_string.h:35
Namespace of classes to measure time in benchmarks.
auto operator<<(std::ostream &stream, const MeasurerName &val) -> std::ostream &
Format to a stream.
auto operator!=(const MeasurerName &lhs, const MeasurerName &rhs) noexcept -> bool
Compare two MeasurerName objects.
Namespace of utility functions and classes.
Namespace of stat_bench source codes.
STL namespace.
auto format(const stat_bench::measurer::MeasurerName &val, fmt::format_context &context) const -> fmt::format_context::iterator
Format.
Definition of Utf8String class.