Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Concepts.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2023, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include <algorithm>
23#include <array>
24#include <cstddef>
25#include <string_view>
26#include <type_traits>
27
28namespace util {
29
33template <typename T>
34concept SomeNumberType = std::is_arithmetic_v<T> && !std::is_same_v<T, bool> && !std::is_const_v<T>;
35
42static consteval auto
43hasNoDuplicates(auto&&... values)
44{
45 auto store = std::array{values...};
46 auto end = store.end();
47 std::ranges::sort(store);
48 return (std::unique(std::begin(store), end) == end);
49}
50
57template <typename... Types>
58constexpr bool
60{
61 constexpr std::array<std::string_view, sizeof...(Types)> kNAMES = {Types::kNAME...};
62 return !std::ranges::any_of(kNAMES, [&](std::string_view const& name1) {
63 return std::ranges::any_of(kNAMES, [&](std::string_view const& name2) {
64 return &name1 != &name2 && name1 == name2; // Ensure different elements are compared
65 });
66 });
67}
68
69} // namespace util
Specifies a number type.
Definition Concepts.hpp:34
This namespace contains various utilities.
Definition AccountUtils.hpp:30
static consteval auto hasNoDuplicates(auto &&... values)
Checks that the list of given values contains no duplicates.
Definition Concepts.hpp:43
constexpr bool hasNoDuplicateNames()
Checks that the list of given type contains no duplicates.
Definition Concepts.hpp:59