Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
symbol_id.hpp
Go to the documentation of this file.
1#ifndef SYMBOL_ID_HPP
2#define SYMBOL_ID_HPP
3
4#include <string>
5#include <string_view>
6#include <algorithm>
16inline std::string to_upper_copy(std::string_view s) {
17 std::string out(s.begin(), s.end());
18 std::transform(out.begin(), out.end(), out.begin(),
19 [](unsigned char c){ return std::toupper(c); });
20 return out;
21}
22
31template <class Tag>
32class SymbolId {
33public:
35 SymbolId() = default;
36
38 explicit SymbolId(std::string name) : name_(std::move(name)) {}
39
41 const std::string& str() const { return name_; }
42
44 explicit operator const std::string&() const { return name_; }
45
47 bool empty() const { return name_.empty(); }
48
49 friend bool operator==(const SymbolId& a, const SymbolId& b) { return a.name_ == b.name_; }
50 friend bool operator!=(const SymbolId& a, const SymbolId& b) { return !(a==b); }
51 friend bool operator<(const SymbolId& a, const SymbolId& b) { return a.name_ < b.name_; }
52
53private:
54 std::string name_;
55};
56
60namespace std {
61 template<class Tag>
62 struct hash<SymbolId<Tag>> {
63 std::size_t operator()(const SymbolId<Tag>& id) const noexcept {
64 return std::hash<std::string>{}(id.str());
65 }
66 };
67}
68
69#endif
Returns an uppercase copy of the input string.
friend bool operator==(const SymbolId &a, const SymbolId &b)
Case-insensitive equality comparison for SymbolId<Tag>.
Definition symbol_id.hpp:49
friend bool operator!=(const SymbolId &a, const SymbolId &b)
Definition symbol_id.hpp:50
SymbolId(std::string name)
Constructs an identifier from a string.
Definition symbol_id.hpp:38
const std::string & str() const
Returns the underlying string.
Definition symbol_id.hpp:41
SymbolId()=default
Constructs an empty identifier.
friend bool operator<(const SymbolId &a, const SymbolId &b)
Case-insensitive strict ordering for SymbolId<Tag>.
Definition symbol_id.hpp:51
bool empty() const
Returns true if the identifier is empty.
Definition symbol_id.hpp:47
Hash specialization for SymbolId<Tag>.
Definition BlockName.h:353
std::size_t operator()(const SymbolId< Tag > &id) const noexcept
Definition symbol_id.hpp:63
std::string to_upper_copy(std::string_view s)
Returns an uppercase copy of the input string.
Definition symbol_id.hpp:16