Sharg 1.1.2-rc.1
The argument parser for bio-c++ tools.
Loading...
Searching...
No Matches
enumeration_names.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <iostream>
13#include <string_view>
14#include <unordered_map>
15
16#include <sharg/platform.hpp>
17
18namespace sharg::custom
19{
20
46template <typename t>
47struct parsing
48{}; // forward
49
51template <typename t>
52struct parsing<t const> : parsing<t>
53{};
54
55template <typename t>
56struct parsing<t &> : parsing<t>
57{};
58
59template <typename t>
60struct parsing<t const &> : parsing<t>
61{};
63
64} // namespace sharg::custom
65
66namespace sharg::detail
67{
70template <size_t I>
73 // Doxygen fail
74 : priority_tag<I - 1>
76{};
77
79template <>
80struct priority_tag<0>
81{};
82
83} // namespace sharg::detail
84
85namespace sharg::detail::adl_only
86{
87
89template <typename t>
91
95template <typename option_t>
97{
101 constexpr enumeration_names_cpo() = default;
103 constexpr enumeration_names_cpo(enumeration_names_cpo const &) = default;
107
111 template <typename option_type>
116
120 template <typename option_type = option_t>
127
137 template <typename option_type = option_t>
138 static constexpr auto cpo_overload(sharg::detail::priority_tag<0>) noexcept(
140 -> decltype(enumeration_names(option_or_type_identity<option_type>{}))
141 {
142 return enumeration_names(option_or_type_identity<option_type>{});
143 }
144
156 template <typename... args_t, typename option_type = option_t /*circumvent incomplete types*/>
157 constexpr auto operator()(args_t &&... args) const
160 {
162 }
163};
164
165} // namespace sharg::detail::adl_only
166
167namespace sharg
168{
169
211// clang-format off
212template <typename option_type>
213 requires requires { { detail::adl_only::enumeration_names_cpo<option_type>{}() }; }
215// clang-format on
217
233// clang-format off
234template <typename option_type>
235concept named_enumeration = requires
236{
237 { sharg::enumeration_names<option_type> };
238};
239// clang-format on
240} // namespace sharg
241
243namespace std
244{
245
250template <typename option_type>
252inline ostream & operator<<(ostream & s, option_type && op)
253{
254 for (auto & [key, value] : sharg::enumeration_names<option_type>)
255 {
256 if (op == value)
257 return s << key;
258 }
259
260 return s << "<UNKNOWN_VALUE>";
261}
262
263} // namespace std
Checks whether the free function sharg::enumeration_names can be called on the type.
Definition enumeration_names.hpp:235
std::unordered_map< std::string_view, t > enumeration_names(t)=delete
Poison-pill overload to prevent non-ADL forms of unqualified lookup.
auto const enumeration_names
Return a conversion map from std::string_view to option_type.
Definition enumeration_names.hpp:214
T is_same_v
Provides platform and dependency checks.
A type that can be specialised to provide customisation point implementations for the sharg::parser s...
Definition enumeration_names.hpp:48
Customization Point Object (CPO) definition for sharg::enumeration_names.
Definition enumeration_names.hpp:97
constexpr enumeration_names_cpo & operator=(enumeration_names_cpo &&)=default
Defaulted.
static constexpr auto cpo_overload(sharg::detail::priority_tag< 0 >) noexcept(noexcept(enumeration_names(option_or_type_identity< option_type >{}))) -> decltype(enumeration_names(option_or_type_identity< option_type >{}))
CPO overload (check 2 out of 2): argument dependent lookup (ADL), i.e. enumeration_names(option_type{...
Definition enumeration_names.hpp:138
constexpr auto operator()(args_t &&... args) const noexcept(noexcept(cpo_overload(sharg::detail::priority_tag< 1 >{}, std::forward< args_t >(args)...))) -> decltype(cpo_overload(sharg::detail::priority_tag< 1 >{}, std::forward< args_t >(args)...))
SFINAE-friendly call-operator to resolve the CPO overload.
Definition enumeration_names.hpp:157
constexpr enumeration_names_cpo & operator=(enumeration_names_cpo const &)=default
constexpr enumeration_names_cpo()=default
Defaulted.
constexpr enumeration_names_cpo(enumeration_names_cpo const &)=default
Defaulted.
static constexpr auto cpo_overload(sharg::detail::priority_tag< 1 >) noexcept(noexcept(sharg::custom::parsing< option_type >::enumeration_names)) -> decltype(sharg::custom::parsing< option_type >::enumeration_names)
CPO overload (check 1 out of 2): explicit customisation via sharg::custom::parsing
Definition enumeration_names.hpp:121
constexpr enumeration_names_cpo(enumeration_names_cpo &&)=default
Defaulted.
A tag that allows controlled overload resolution via implicit base conversion rules.
Definition enumeration_names.hpp:76
Hide me