OpenLB 1.7
Loading...
Searching...
No Matches
typeMap.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2021 Adrian Kummerlaender
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#ifndef UTILITIES_TYPE_MAP_H
25#define UTILITIES_TYPE_MAP_H
26
27#include "core/meta.h"
28
29namespace olb {
30
31namespace meta {
32
33template <typename...>
35
36template <typename KEY, typename VALUE, typename... TAIL>
37struct unzip_flattened_keys<KEY,VALUE,TAIL...> {
38 static_assert(sizeof...(TAIL) % 2 == 0, "TAIL must be valid map size");
39 using type = typename unzip_flattened_keys<TAIL...>::type::template push<KEY>;
40};
41
42template <>
44 using type = list<>;
45};
46
47template <typename...>
49
50template <typename KEY, typename VALUE, typename... TAIL>
51struct unzip_flattened_values<KEY,VALUE,TAIL...> {
52 static_assert(sizeof...(TAIL) % 2 == 0, "TAIL must be valid map size");
53 using type = typename unzip_flattened_values<TAIL...>::type::template push<VALUE>;
54};
55
56template <>
58 using type = list<>;
59};
60
61template <typename KEYS, typename VALUES>
62struct plain_map {
63 using keys_t = KEYS;
64 using values_t = VALUES;
65
66 static_assert(keys_t::size == values_t::size,
67 "Count of keys and values must match");
68
69 static constexpr unsigned size = keys_t::size;
70
71 template <typename KEY>
72 using value = typename values_t::template get<(keys_t::template index<KEY>())>;
73
74 template <template<typename> typename F>
76
77 template <typename F>
78 static constexpr void for_each(F f) {
79 KEYS::for_each([&](auto key) {
80 f(key, meta::id<value<typename decltype(key)::type>>{});
81 });
82 }
83
84};
85
87template <typename... KVs>
88using map = plain_map<
89 typename unzip_flattened_keys<KVs...>::type,
90 typename unzip_flattened_values<KVs...>::type
91>;
92
93}
94
95}
96
97#endif
Top level namespace for all of OpenLB.
Identity type to pass non-constructible types as value.
Definition meta.h:79
Plain wrapper for list of types.
Definition meta.h:276
static constexpr void for_each(F f)
Definition typeMap.h:78
static constexpr unsigned size
Definition typeMap.h:69
typename values_t::template get<(keys_t::template index< KEY >())> value
Definition typeMap.h:72
typename unzip_flattened_keys< TAIL... >::type::template push< KEY > type
Definition typeMap.h:39
typename unzip_flattened_values< TAIL... >::type::template push< VALUE > type
Definition typeMap.h:53