MOTION  0.01
Framework for mixed-protocol multi-party computation
meta.hpp
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2020 Lennart Braun
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 
23 #pragma once
24 
25 #include <boost/hana/at_key.hpp>
26 #include <boost/hana/map.hpp>
27 #include <boost/hana/tuple.hpp>
28 
29 namespace encrypto::motion {
30 
31 // TypeMap is a compile-time map whose keys are types that are mapped to
32 // objects of possibly different types depending on the key
33 // e.g. TypeMap<std::vector, int, std::string> maps
34 // - int (as type) to an std::vector<int> instance, and
35 // - std::string to an std::vector<int> instance.
36 // Note: latest clang does not support lambdas in unevaluated environments yet.
37 
38 #if __cplusplus > 201703L && !defined(__clang__) // C++20
39 
40 template <template <typename> class Value, typename... Ts>
41 using TypeMap = decltype([] {
42  return boost::hana::unpack(boost::hana::tuple_t<Ts...>, [](auto... t) {
43  return boost::hana::make_map(
44  boost::hana::make_pair(decltype(t)(), Value<typename decltype(t)::type>())...);
45  });
46 }());
47 
48 #else // C++17
49 
50 namespace detail {
51 
52 template <template <typename> class Value, typename... Ts>
53 auto MakeTypeMap() {
54  return boost::hana::unpack(boost::hana::tuple_t<Ts...>, [](auto... t) {
55  return boost::hana::make_map(
56  boost::hana::make_pair(decltype(t)(), Value<typename decltype(t)::type>())...);
57  });
58 }
59 
60 } // namespace detail
61 
62 template <template <typename> class Value, typename... Ts>
63 using TypeMap = decltype(detail::MakeTypeMap<Value, Ts...>());
64 
65 #endif
66 
67 } // namespace encrypto::motion
encrypto::motion::detail::MakeTypeMap
auto MakeTypeMap()
Definition: meta.hpp:53
geninput.type
type
Definition: geninput.py:149
encrypto::motion::TypeMap
decltype(detail::MakeTypeMap< Value, Ts... >()) TypeMap
Definition: meta.hpp:63
encrypto::motion
Definition: algorithm_description.cpp:35