I have a class like the following:
template<typename ... TTypes>
class Composite {
public:
//Composite() : null(true) { }
Composite(TTypes... values) : values(std::make_tuple(values...)), null(false) { }
private:
bool null;
std::tuple<TTypes...> values;
};
int main(int argc, char *argv[]) {
Composite<int, char, int> a1;
}
But this leads to an error because the second constructor would override the first one with TTypes = {}. Is there any way to keep the empty constructor?
Best, Moritz
Since none of the existing answers so actually solve the problem, but there is a solution by Piotr Skotnicki hidden in the comments, I'm just gonna repost it here for visibility:
#include <tuple>
#include <type_traits>
template<typename ... TTypes>
class Composite {
public:
Composite() : null(true) { }
template <std::size_t N = sizeof...(TTypes), typename std::enable_if<(N>0), int>::type = 0>
Composite(TTypes... values) : values(std::make_tuple(values...)), null(false) { }
private:
bool null;
std::tuple<TTypes...> values;
};
int main(int argc, char *argv[]) {
Composite<int, char, int> a1;
Composite<> a2;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With