Created
April 18, 2018 02:34
-
-
Save jmal0/0b4c22f0c72a4c516684caea7793a055 to your computer and use it in GitHub Desktop.
append to variadic template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <template_append.hpp> | |
#include <tuple> | |
#define WITH_INT | |
#define WITH_DOUBLE | |
using type0 = std::tuple<>; | |
#ifdef WITH_INT | |
using type1 = JMAL::template_append<int, type0>::type; | |
#else | |
using type1 = JMAL::template_append<void, type0>::type; | |
#endif | |
#ifdef WITH_DOUBLE | |
using type2 = JMAL::template_append<double, type1>::type; | |
#else | |
using type2 = JMAL::template_append<void, type1>::type; | |
#endif | |
#if defined(WITH_INT) and defined(WITH_DOUBLE) | |
static_assert(std::is_same<type2, | |
std::tuple<int, double>>::value, | |
"Didn't work"); | |
#elif defined(WITH_INT) | |
static_assert(std::is_same<type2, | |
std::tuple<int>>::value, | |
"Didn't work"); | |
#elif defined(WITH_DOUBLE) | |
static_assert(std::is_same<type2, | |
std::tuple<double>>::value, | |
"Didn't work"); | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _JMAL_TEMPLATE_APPEND_H | |
#define _JMAL_TEMPLATE_APPEND_H | |
namespace JMAL | |
{ | |
template <typename T, typename Seq> | |
struct template_append; | |
template <typename T, template<typename...> class Seq, typename... Args> | |
struct template_append<T, Seq<Args...>> | |
{ | |
using type = Seq<Args..., T>; | |
}; | |
template <template<typename...> class Seq, typename... Args> | |
struct template_append<void, Seq<Args...>> | |
{ | |
using type = Seq<Args...>; | |
}; | |
} // namespace JMAL | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment