numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
log_tag_element.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 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 <string>
25#include <utility>
26
28
30
37public:
43 explicit log_tag_element(std::string name)
44 : name_(std::move(name)), hash_(util::hash_string(name_)) {}
45
51 [[nodiscard]] auto name() const noexcept -> const std::string& {
52 return name_;
53 }
54
60 [[nodiscard]] auto hash() const noexcept -> std::size_t { return hash_; }
61
69 [[nodiscard]] auto operator==(const log_tag_element& right) const noexcept
70 -> bool {
71 return (hash_ == right.hash_) && (name_ == right.name_);
72 }
73
81 [[nodiscard]] auto operator!=(const log_tag_element& right) const noexcept
82 -> bool {
83 return !operator==(right);
84 }
85
86private:
88 std::string name_;
89
91 std::size_t hash_;
92};
93
94} // namespace num_collect::logging::impl
95
96namespace std {
97
102template <>
103struct hash<num_collect::logging::impl::log_tag_element> {
104public:
107
109 using result_type = std::size_t;
110
117 [[nodiscard]] auto operator()(const argument_type& key) const noexcept
118 -> result_type {
119 return key.hash();
120 }
121};
122
123} // namespace std
auto operator==(const log_tag_element &right) const noexcept -> bool
Compare with another object.
log_tag_element(std::string name)
Constructor.
auto hash() const noexcept -> std::size_t
Get the hash number.
auto name() const noexcept -> const std::string &
Get the name.
auto operator!=(const log_tag_element &right) const noexcept -> bool
Compare with another object.
Definition of hash_string function.
Namespace of internal implementations.
Namespace of num_collect source codes.
STL namespace.
auto operator()(const argument_type &key) const noexcept -> result_type
Get the hash number.