129 template<
typename T, string_literal... NAMES>
requires (
sizeof...(NAMES) == 0) || (concepts::gettable<T> && (
sizeof...(NAMES) == std::tuple_size_v<std::decay_t<T>>))
136 template<
size_t IDX>
requires (IDX <
sizeof...(NAMES))
137 static constexpr auto name = std::get<IDX>(std::make_tuple(NAMES...));
140 static constexpr auto names = std::make_tuple(NAMES...);
143 template<
string_literal NAME>
144 static constexpr bool has_name = (
named<T,NAMES...>::template _find_name<0,NAME,NAMES...>() !=
sizeof...(NAMES));
147 template<
string_literal NAME>
148 static constexpr size_t find_name =
named<T,NAMES...>::template _find_name<0,NAME,NAMES...>();
151 static constexpr size_t size =
sizeof...(NAMES);
154 template<
typename... Ts>
155 constexpr named(Ts&&...ts) : T{
std::forward<Ts>(ts)...} {}
158 template<
typename U,
string_literal... UNAMES>
requires (
sizeof...(NAMES) ==
sizeof...(UNAMES))
162 template<
typename U,
string_literal... UNAMES>
requires (
sizeof...(NAMES) ==
sizeof...(UNAMES))
166 template<
typename U,
string_literal... UNAMES>
requires (
sizeof...(NAMES) ==
sizeof...(UNAMES))
169 ((this->
template get<UNAMES>() = src.
template get<UNAMES>()), ...);
174 template<
typename... Ts>
requires (
sizeof...(NAMES) ==
sizeof...(Ts))
175 named operator=(
const std::tuple<Ts...>& src)
182 constexpr T&
values(
void) {
return *
this; }
183 constexpr const T&
values(
void)
const {
return *
this; }
185 constexpr operator T(
void) {
return values(); }
189 template<
size_t IDX>
constexpr decltype(
auto)
get(
void) {
return std::get<IDX>(values()); }
190 template<
size_t IDX>
constexpr decltype(
auto)
get(
void)
const {
return std::get<IDX>(values()); }
195 constexpr size_t idx = _find_name<0,NAME,NAMES...>();
196 static_assert( idx <
sizeof...(NAMES),
"named structure does not contain requested name.");
199 if constexpr (
sizeof...(SUBNAME) == 0)
return get<idx>();
200 else return get<idx>().template
get<SUBNAME...>();
206 constexpr size_t idx = _find_name<0,NAME,NAMES...>();
207 static_assert( idx <
sizeof...(NAMES),
"named structure does not contain requested name.");
210 if constexpr (
sizeof...(SUBNAME) == 0)
return get<idx>();
211 else return get<idx>().template
get<SUBNAME...>();
221 if constexpr (idx != 0) s <<
", ";
224 s << n.template name<idx> <<
" = ";
227 if constexpr (bbm::is_string_type_v< std::tuple_element_t<idx, named> >) s << std::string(
"\"") + std::get<idx>(n) << std::string(
"\"");
230 else s << std::get<idx>(n);
240 if constexpr (NAME == N)
return IDX;
241 else if constexpr (
sizeof...(Ns) != 0)
return _find_name<IDX+1, NAME, Ns...>();
242 else return sizeof...(NAMES);
250 template<
typename T>
struct is_named : std::false_type {};
263 if constexpr (is_named_v<T>)
return t.values();
264 else return std::forward<T>(t);
268 using anonymize_t = std::decay_t<decltype(anonymize_v(std::declval<T>()))>;
275 template<
typename U,
typename T>
struct include_names_from : std::false_type {};
276 template<
typename U,
typename T,
string_literal... NAMES>
requires is_named_v<U>
277 struct include_names_from<U,
named<T,NAMES...>>: std::bool_constant< (U::template has_name<NAMES> && ...) > {};
281 template<
typename U,
typename V>
requires is_named_v<U> && is_named_v<V>
282 struct named_equivalence<U,V> : std::conjunction< bbm::detail::include_names_from<std::decay_t<U>,std::decay_t<V>>, bbm::detail::include_names_from<std::decay_t<V>,std::decay_t<U>> > {};
284 template<
typename U,
typename V>
298 template<string_literal... NAMES,
typename... Ts>
requires (
sizeof...(NAMES) ==
sizeof...(Ts))
299 constexpr auto make_named(Ts&&... ts) {
return make_named<NAMES...>(std::make_tuple(std::forward<Ts>(ts)...)); }
304 template<string_literal... NAMES,
typename T>
requires is_named_v<T>
305 constexpr auto pick(T&& t) {
return make_named<NAMES...>(get<NAMES>(std::forward<T>(t))...); }
310 template<string_literal... NAMES,
typename... Ts>
requires (
sizeof...(NAMES) ==
sizeof...(Ts))
311 named<std::tuple<Ts&...>, NAMES...>
tie(Ts&&... src) {
return std::tie(std::forward<Ts>(src)...); }
316 template<string_literal NAME, string_literal... SUBNAME,
typename T>
requires is_named_v<T>
317 inline constexpr decltype(
auto)
get(T&& src) {
return src.template
get<NAME, SUBNAME...>(); }
319 template<string_literal NAME, string_literal... SUBNAME,
typename T>
requires is_named_v<T>
320 inline constexpr decltype(
auto)
get(
const T& src) {
return src.template
get<NAME, SUBNAME...>(); }
329 struct tuple_size<
bbm::named<T,NAMES...>> : tuple_size<T> {};
333 struct tuple_element<idx,
bbm::named<T,NAMES...>> : tuple_element<idx, T> {};
std::get supported
Definition: util.h:175
#define CONSTFOR(IDX, NUMITR,...)
HELPER MACRO.
Definition: constfor.h:63
Additional convenience methods for named tuples.
Definition: aggregatebsdf.h:29
constexpr named< anonymize_t< T >, NAMES... > make_named(T &&t)
Make a named of a gettable type (with size == #NAMES); renames if the type is a named container.
Definition: named.h:293
constexpr bool is_named_v
Definition: named.h:254
named< std::tuple< Ts &... >, NAMES... > tie(Ts &&... src)
Tie by name.
Definition: named.h:311
static constexpr bool named_equivalence_v
Definition: named.h:285
constexpr decltype(auto) anonymize_v(T &&t)
Definition: named.h:261
constexpr auto pick(T &&t)
Pick a subset/reshuffle a named container T and return as a named tuple.
Definition: named.h:305
size_t size(T &&t)
Definition: iterator_util.h:22
constexpr decltype(auto) get(T &&src)
Definition: named.h:317
std::decay_t< decltype(anonymize_v(std::declval< T >()))> anonymize_t
Definition: named.h:268
decltype(auto) value(T &&t)
return the value of an attribute, or if not an attribute the object
Definition: attribute_value.h:20
named container
Definition: named.h:131
constexpr decltype(auto) get(void) const
Definition: named.h:203
constexpr T & values(void)
\names Querry/cast values from the underlying container
Definition: named.h:182
constexpr decltype(auto) get(void)
Definition: named.h:189
constexpr named(const named< U, UNAMES... > &src)
Reshuffle constructor (based on matching names)
Definition: named.h:163
friend std::ostream & operator<<(std::ostream &s, const named &n)
ostream
Definition: named.h:216
constexpr decltype(auto) get(void)
Definition: named.h:192
constexpr named(named< U, UNAMES... > &&src)
Reshuffle constructor (based on matching names)
Definition: named.h:159
constexpr const T & values(void) const
Definition: named.h:183
static constexpr size_t _find_name(void)
Definition: named.h:238
constexpr named(Ts &&...ts)
Forwarding constructor.
Definition: named.h:155
constexpr decltype(auto) get(void) const
Definition: named.h:190
T value_type
Definition: named.h:133
Definition: string_literal.h:16
Additional basic helper concepts.