Hedgehog  3.1.0
A library to generate hybrid pipeline workflow systems
Loading...
Searching...
No Matches
meta_functions.h
Go to the documentation of this file.
1// NIST-developed software is provided by NIST as a public service. You may use, copy and distribute copies of the
2// software in any medium, provided that you keep intact this entire notice. You may improve, modify and create
3// derivative works of the software or any portion of the software, and you may copy and distribute such modifications
4// or works. Modified works should carry a notice stating that you changed the software and should note the date and
5// nature of any such change. Please explicitly acknowledge the National Institute of Standards and Technology as the
6// source of the software. NIST-developed software is expressly provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND,
7// EXPRESS, IMPLIED, IN FACT OR ARISING BY OPERATION OF LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
8// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT AND DATA ACCURACY. NIST NEITHER REPRESENTS NOR
9// WARRANTS THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ANY DEFECTS WILL BE
10// CORRECTED. NIST DOES NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF THE SOFTWARE OR THE RESULTS
11// THEREOF, INCLUDING BUT NOT LIMITED TO THE CORRECTNESS, ACCURACY, RELIABILITY, OR USEFULNESS OF THE SOFTWARE. You
12// are solely responsible for determining the appropriateness of using and distributing the software and you assume
13// all risks associated with its use, including but not limited to the risks and costs of program errors, compliance
14// with applicable laws, damage to or loss of data, programs or equipment, and the unavailability or interruption of
15// operation. This software is not intended to be used in any situation where a failure could cause risk of injury or
16// damage to property. The software developed by NIST employees is not subject to copyright protection within the
17// United States.
18
19
20
21#ifndef HEDGEHOG_META_FUNCTIONS_H
22#define HEDGEHOG_META_FUNCTIONS_H
23
24#pragma once
25#include <iostream>
26#include <tuple>
27
28//todo clean code
29
31namespace hh {
32
33#ifndef DOXYGEN_SHOULD_SKIP_THIS
35namespace core {
37namespace abstraction {
38
41template<class Input>
42class ReceiverAbstraction;
43
46template<class Output>
47class SenderAbstraction;
48}
49}
50#endif //DOXYGEN_SHOULD_SKIP_THIS
51
53namespace tool {
54
56namespace internals {
57
61template<typename Ts, typename T>
62struct PushFront;
63
67template<typename... Vs, typename T>
68struct PushFront<std::tuple<Vs...>, T> {
70 using Type = std::tuple<T, Vs...>;
71};
72
74template<typename Ts, typename T>
76
80template<typename Types, typename Indices>
82
86template<typename Types, size_t... Indices>
87struct SplitInput<Types, std::index_sequence<Indices...>> {
89 using Type = std::tuple<std::tuple_element_t<Indices, Types>...>;
90};
91
93template<typename Types, typename Indices>
95
100template<typename Types, size_t delta, typename Indices>
102
107template<typename Types, size_t delta, size_t... Indices>
108struct SplitOutput<Types, delta, std::index_sequence<Indices...>> {
110 using Type = std::tuple<std::tuple_element_t<delta + Indices, Types>...>;
111};
112
114template<typename Types, size_t delta, typename Indices>
116
120template<size_t delimiter, typename ... Types>
121struct Splitter {
122 static_assert(delimiter != 0, "The delimiter should not be 0.");
123 static_assert(delimiter < sizeof...(Types), "The delimiter should be inferior to the number of types.");
124
126 using Inputs = internals::SplitInput_t<std::tuple<Types...>, std::make_integer_sequence<size_t, delimiter>>;
127
129 using Outputs = internals::SplitOutput_t<std::tuple<Types...>,
130 delimiter,
131 std::make_integer_sequence<size_t, sizeof...(Types) - delimiter>>;
132};
133
137template<typename T, typename Tuple>
138struct HasType;
139
142template<typename T>
143struct HasType<T, std::tuple<>> : std::false_type {};
144
149template<typename T, typename Front, typename... Ts>
150struct HasType<T, std::tuple<Front, Ts...>> : HasType<T, std::tuple<Ts...>> {};
151
155template<typename T, typename... Ts>
156struct HasType<T, std::tuple<T, Ts...>> : std::true_type {};
157
163template<typename T1, typename T2, size_t Index, size_t Size>
164struct IntersectImpl;
165
170template<typename T1, typename T2, size_t Size>
171struct IntersectImpl<T1, T2, Size, Size> {
173 using type = std::tuple<>;
174};
175
181template<typename T1, typename T2, size_t Index, size_t Size>
184 using type = std::conditional_t<
188};
189
193template<typename T1, typename T2>
194struct Intersect {
197};
198}
199
201template<size_t delta, typename ... Types>
202using Inputs = typename internals::Splitter<delta, Types...>::Inputs;
203
205template<size_t delta, typename ... Types>
206using Outputs = typename internals::Splitter<delta, Types...>::Outputs;
207
209template<class Tuple1, class Tuple2>
211
215template<class T, class ...Ts>
216constexpr bool isContainedIn_v = std::disjunction_v<std::is_same<T, Ts>...>;
217
221template<class T, class Tuple>
222constexpr bool isContainedInTuple_v = std::tuple_size_v<Intersect_t<std::tuple<T>, Tuple>> == 1;
223
227template<typename T>
228constexpr auto typeToStrView() {
229 std::string_view name, prefix, suffix;
230#ifdef __clang__
231 name = __PRETTY_FUNCTION__;
232 prefix = "auto hh::tool::typeToStr() [T = ";
233 suffix = "]";
234#elif defined(__GNUC__)
235 name = __PRETTY_FUNCTION__;
236 prefix = "constexpr auto hh::tool::typeToStrView() [with T = ";
237 suffix = "]";
238#elif defined(_MSC_VER)
239 name = __FUNCSIG__;
240 prefix = "auto __cdecl typeToStr<";
241 suffix = ">(void)";
242#endif
243 name.remove_prefix(prefix.size());
244 name.remove_suffix(suffix.size());
245
246 return name;
247}
248
252template<typename T>
253constexpr auto typeToStr() { return std::string(typeToStrView<T>()); }
254
255}
256}
257
258#endif //HEDGEHOG_META_FUNCTIONS_H
Hedgehog main namespace.
typename internals::Intersect< Tuple1, Tuple2 >::type Intersect_t
Helper getting the intersection of types between two type tuples.
constexpr auto typeToStrView()
Create a string_view containing the type name.
constexpr auto typeToStr()
Create a string containing the type name.
constexpr bool isContainedInTuple_v
Helper testing if a type is in a tuple of types.
typename internals::Splitter< delta, Types... >::Inputs Inputs
Helper getting the input types from a list of template types (variadic)
typename internals::Splitter< delta, Types... >::Outputs Outputs
Helper getting the output types from a list of template types (variadic)
constexpr bool isContainedIn_v
Helper testing if a type T is in variadic Ts.
typename SplitInput< Types, Indices >::Type SplitInput_t
Helper getting the input types in a tuple.
typename PushFront< Ts, T >::Type PushFront_t
Helper creating a tuple from a tuple Ts in wish we have added on front the type T.
typename SplitOutput< Types, delta, Indices >::Type SplitOutput_t
Helper to output types of a tuple.
Base definition of PushFront accepting a tuple as template parameter and the element to add.
std::tuple< T, Vs... > Type
Accessor of the tuple type consisting of the type T followed by the Vs...
Base definition of SplitInput splitting a tuple of type to get the input types.
std::tuple< std::tuple_element_t< Indices, Types >... > Type
Type accessor.
Base definition of SplitOutput_t splitting a tuple of type to get the output types.
std::tuple< std::tuple_element_t< delta+Indices, Types >... > Type
Type accessor.
Metafunction splitting a variadic to input and output types at a specific delimiter.
internals::SplitOutput_t< std::tuple< Types... >, delimiter, std::make_integer_sequence< size_t, sizeof...(Types) - delimiter > > Outputs
Type accessor of the output types.
internals::SplitInput_t< std::tuple< Types... >, std::make_integer_sequence< size_t, delimiter > > Inputs
Type accessor of the input types.
Base definition of HasType testing if a type T is in tuple Tuple.
Base definition of the implementation of the Intersect metafunction.
std::conditional_t< internals::HasType< std::tuple_element_t< Index, T1 >, T2 >::value, internals::PushFront_t< typename IntersectImpl< T1, T2, Index+1, Size >::type, std::tuple_element_t< Index, T1 > >, typename IntersectImpl< T1, T2, Index+1, Size >::type > type
Accessor to the type of the tuple representing the intersection between two tuples.
std::tuple<> type
Returning an empty tuple when arriving at the end of T1.
Intersect metafunction creating a tuple of types that are in T1 and T2.
typename IntersectImpl< T1, T2, 0, std::tuple_size_v< T1 > >::type type
Accessor to the type of the tuple of types that are in T1 and T2.