Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
AbstractionHelpers.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <ext/tuple>
9#include <ext/array>
10#include <ext/typeinfo>
11
14
15namespace abstraction {
16
17namespace detail {
18
19template < class ... ParamTypes, class F, class Tuple, std::size_t... I >
20constexpr decltype ( auto ) apply_impl ( F && f, Tuple && t, std::index_sequence < I ... > ) {
21 return std::invoke ( std::forward < F > ( f ), abstraction::retrieveValue < ParamTypes > ( std::get < I > ( std::forward < Tuple > ( t ) ) ) ... );
22}
23
24} // namespace detail
25
26template < class ... ParamTypes, class F, class Tuple >
27constexpr decltype ( auto ) apply ( F && f, Tuple && t ) {
28 return detail::apply_impl < ParamTypes ... > ( std::forward < F > ( f ), std::forward < Tuple > ( t ), std::make_index_sequence < sizeof ... ( ParamTypes ) > { } );
29}
30
31template < class ... Params >
32static ext::type_index paramType ( unsigned index ) {
33 ext::type_index res ( typeid ( void ) );
34
35 auto lambda = [ & ] ( auto I ) {
36 res = ext::type_index ( typeid ( std::tuple_element_t < decltype ( I )::value, std::tuple < Params ... > > ) );
37 };
38
39 ext::constexpr_switch < sizeof ... ( Params ) > ( index, lambda );
40
41 return res;
42}
43
44template < class ... Params >
47
48 auto lambda = [ & ] ( auto I ) {
49 res = abstraction::TypeQualifiers::typeQualifiers < std::tuple_element_t < decltype ( I )::value, std::tuple < Params ... > > > ( );
50 };
51
52 ext::constexpr_switch < sizeof ... ( Params ) > ( index, lambda );
53
54 return res;
55}
56
57} /* namespace abstraction */
58
TypeQualifierSet
Definition: TypeQualifiers.hpp:15
static constexpr TypeQualifierSet typeQualifiers()
Definition: TypeQualifiers.hpp:52
Definition: typeindex.h:37
constexpr decltype(auto) apply_impl(F &&f, Tuple &&t, std::index_sequence< I ... >)
Definition: AbstractionHelpers.hpp:20
Definition: AlgorithmAbstraction.hpp:11
constexpr decltype(auto) apply(F &&f, Tuple &&t)
Definition: AbstractionHelpers.hpp:27
abstraction::TypeQualifiers::TypeQualifierSet paramTypeQualifiers(unsigned index)
Definition: AbstractionHelpers.hpp:45
return res
Definition: MinimizeByPartitioning.h:145
void constexpr_switch(const std::size_t i, F &&f)
Definition: utility.hpp:65