Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Concepts.hpp
1#pragma once
2
3#include <algorithm>
4#include <array>
5#include <chrono>
6#include <concepts>
7#include <cstddef>
8#include <string_view>
9#include <type_traits>
10
11namespace util {
12
18template <typename T>
19concept SomeNumberType = std::is_arithmetic_v<T> && !std::is_same_v<T, bool> && !std::is_const_v<T>;
20
26template <typename T>
27concept SomeSystemClock = requires {
28 { T::now() } -> std::same_as<std::chrono::system_clock::time_point>;
29};
30
37static consteval auto
38hasNoDuplicates(auto&&... values)
39{
40 auto store = std::array{values...};
41 auto end = store.end();
42 std::ranges::sort(store);
43 return (std::unique(std::begin(store), end) == end);
44}
45
52template <typename... Types>
53constexpr bool
55{
56 constexpr std::array<std::string_view, sizeof...(Types)> kNames = {Types::kName...};
57 return !std::ranges::any_of(kNames, [&](std::string_view const& name1) {
58 return std::ranges::any_of(kNames, [&](std::string_view const& name2) {
59 return &name1 != &name2 && name1 == name2; // Ensure different elements are compared
60 });
61 });
62}
63
64} // namespace util
Specifies a number type.
Definition Concepts.hpp:19
Specifies a clock that reports the current time as a system clock time point.
Definition Concepts.hpp:27
This namespace contains various utilities.
Definition HandlerRegistry.hpp:24
static consteval auto hasNoDuplicates(auto &&... values)
Checks that the list of given values contains no duplicates.
Definition Concepts.hpp:38
constexpr bool hasNoDuplicateNames()
Checks that the list of given type contains no duplicates.
Definition Concepts.hpp:54