[Solved] Turning a BOUNDED std::list of parameters into a type std::tuple tup

This code works correctly on clang and g++ (using C++11): http://coliru.stacked-crooked.com/a/c8071ab447e10a31 Produces a std::tuple with Max_N elements of the same type, and fills it up with the first values of the given list. If less elements in list than Max_N, fills the last elements with sentinel values. In practice, using std::array<C, N> may be more … Read more

[Solved] Is there a way to define Variadic template macro?

__VA_ARGS__ can be used multiple times, so you could write: #define PARSE_FUNCTION(functionName, …) \ std::function<int(__VA_ARGS__)> m_##functionName() { \ return std::function<int(__VA_ARGS__)>(functionName); \ } What is happening is just simple text substitution, whether the arguments is for a template or not won’t be checked by the preprocessor. Actually any function objects can be implicitly converted to a … Read more

[Solved] Transform std::pair to std::tuple with any number of elements

Option #1 #include <cstddef> #include <type_traits> #include <utility> #include <tuple> template <typename A, typename B> struct merge_tuples { static_assert(std::tuple_size<A>::value == std::tuple_size<B>::value, “!”); template <std::size_t… Is> static auto merge(std::index_sequence<Is…>) noexcept -> std::tuple<typename std::decay<decltype(std::declval<typename std::tuple_element<Is, A>::type>() + std::declval<typename std::tuple_element<Is, B>::type>()) >::type…>; using type = decltype(merge(std::make_index_sequence<std::tuple_size<A>::value>{})); }; DEMO Option #2 #include <type_traits> #include <utility> template <typename A, typename … Read more