Sequoia
Loading...
Searching...
No Matches
Nomenclator.hpp
Go to the documentation of this file.
1
2// Copyright Oliver J. Rosten 2023. //
3// Distributed under the GNU GENERAL PUBLIC LICENSE, Version 3.0. //
4// (See accompanying file LICENSE.md or copy at //
5// https://www.gnu.org/licenses/gpl-3.0.en.html) //
7
8#pragma once
9
14#include <string>
15#include <type_traits>
16
17namespace sequoia::object
18{
19 template<class T>
20 inline constexpr bool has_name_value{
21 requires(const T& t) { { t.name } -> std::convertible_to<std::string>; }
22 };
23
24 template<class T>
25 inline constexpr bool has_name_function{
26 requires(const T& t) { { t.name() } -> std::convertible_to<std::string>; }
27 };
28
29 template<class T>
31 {
32 static std::string name() = delete;
33 static std::string name(const T&) = delete;
34 };
35
36 template<class T>
37 requires has_name_value<T> || has_name_function<T>
38 struct nomenclator<T>
39 {
40 [[nodiscard]]
41 std::string operator()(const T& t) const
42 {
43 if constexpr(has_name_function<T>)
44 return t.name();
45 else
46 return t.name;
47 }
48 };
49
50 template<class T>
51 inline constexpr bool has_extrinsic_nomenclator{
52 requires { { nomenclator<T>{}() } -> std::convertible_to<std::string>; }
53 };
54
55 template<class T>
56 inline constexpr bool has_intrinsic_nomenclator{
57 requires(const T& t) { { nomenclator<T>{}(t) } -> std::convertible_to<std::string>; }
58 };
59
60 template<class T>
61 requires has_intrinsic_nomenclator<T> || has_extrinsic_nomenclator<T>
62 [[nodiscard]]
63 std::string nomenclature([[maybe_unused]] const T& t){
64 if constexpr(has_intrinsic_nomenclator<T>)
65 return nomenclator<T>{}(t);
66 else
67 return nomenclator<T>{}();
68 }
69}
Definition: Nomenclator.hpp:31