LibSWOC++ 1.5.14
Solid Wall of C++
Loading...
Searching...
No Matches
swoc_meta.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright Verizon Media 2020
7
8#pragma once
9
10#include <type_traits>
11#include <utility>
12
13#include "swoc/swoc_version.h"
14
15namespace swoc { inline namespace SWOC_VERSION_NS { namespace meta {
64
66template <unsigned N> struct CaseTag : public CaseTag<N - 1> {
67 constexpr CaseTag() {}
68
69 static constexpr unsigned value = N;
70};
71
73template <> struct CaseTag<0> {
74 constexpr CaseTag() {}
75
76 static constexpr unsigned value = 0;
77};
78
83static constexpr CaseTag<9> CaseArg{};
84
114template <typename T> T TypeFunc();
115
146template <typename T, typename U>
147constexpr auto
148eraser(U &&u) -> U {
149 return std::forward<U>(u);
150}
151
168template <typename... Args> struct vary : public Args... {
169 using Args::operator()...;
170};
171
172template <typename... Args> vary(Args...) -> vary<Args...>;
173
186template <typename T, typename... Types> struct is_any_of {
187 static constexpr bool value = std::disjunction<std::is_same<T, Types>...>::value;
188};
189
190template <typename T, typename... Types> struct is_homogenous {
191 static constexpr bool value = std::conjunction<std::is_same<T, Types>...>::value;
192 using type = T;
193};
194
196template <typename T, typename... Types> inline constexpr bool is_any_of_v = is_any_of<T, Types...>::value;
197
207template <typename... Types> struct type_list {
209 static constexpr size_t size = sizeof...(Types);
210
222 template <template <typename... Pack> typename T> using apply = T<Types...>;
223
237 template <typename T> static constexpr bool contains = is_any_of<T, Types...>::value;
238};
239
257template <typename T> struct let {
258 using self_type = let;
259
260 let(self_type const &that) = delete;
261 self_type &operator=(self_type const &) = delete;
262
263 T &_var;
265
271 let(T &var, T const &value);
272
278 let(T &var, T &&value);
279
280 ~let();
281};
282
283template <typename T> let<T>::let(T &var, T const &value) : _var(var), _value(std::move(var)) {
284 _var = value;
285}
286template <typename T> let<T>::let(T &var, T &&value) : _var(var), _value(std::move(var)) {
287 _var = std::move(value);
288}
289
290template <typename T> let<T>::~let() {
291 _var = std::move(_value);
292}
293
294}}} // namespace swoc::SWOC_VERSION_NS::meta
STL namespace.
For template deduction guides.
Definition ArenaWriter.cc:9
static constexpr unsigned value
Case tag value.
Definition swoc_meta.h:76
Case hierarchy.
Definition swoc_meta.h:66
static constexpr unsigned value
Case tag value.
Definition swoc_meta.h:69
T & _var
Reference to scoped variable.
Definition swoc_meta.h:263
T _value
Original value.
Definition swoc_meta.h:264
static constexpr bool contains
Definition swoc_meta.h:237
T< Types... > apply
Definition swoc_meta.h:222
static constexpr size_t size
Length of the type list.
Definition swoc_meta.h:209
constexpr auto eraser(U &&u) -> U
Definition swoc_meta.h:148