I have that code :
template<typename Type, typename... Extentions>
class Variable : virtual public GenericVar<Type>, public Extentions...
{
static_assert((std::is_base_of_v<GenericVar<Type>, Extentions> && ...), "Only virtual base of GenericVar<T> allowed as variadic.");
public:
template<typename... Args>
Variable(Type initValue, Args... args);
virtual ~Variable();
};
template<typename Type, typename... Extentions>
template<typename... Args>
Variable<Type,Extentions...>::Variable(Type initValue, Args... args) : GenericVar<Type>(), Extentions(args)...
{
this->value = initValue;
}
template<typename Type, typename... Extentions>
Variable<Type,Extentions...>::~Variable()
{
}
usage :
template<typename T>
using Constant = Variable<T, Immutable<T>, Forceable<T>>;
int main(int argc, char *argv[])
{
Variable<float, Forceable<float>> test2(1.2f,nullptr);
Constant<float> constant(4.578f, nullptr, nullptr);
Variable<quint32, Forceable<quint32>, ChangeCheckable<quint32>> value(45, nullptr, nullptr);
}
I'd like to create a generic, extensible class to build all my var types.
and it works great! but...
I haven't found a way to avoid nullptr in the constructor. for example "Forcable" :
template<typename T>
class Forceable : virtual public GenericVar<T>
{
public:
Forceable(std::nullptr_t);
...
...
};
template<typename T>
Forceable<T>::Forceable(std::nullptr_t)
{
this->forced = false;
}
If I remove it, I get this error:
xxxxxxxxxxxxxxxx\main.cpp:16: erreur : mismatched argument pack lengths while expanding 'Extentions'
In file included from xxxxxxxxxxxxxxxx/Variables/Extention/Detectable.h:6,
from xxxxxxxxxxxxxxxx\main.cpp:5:
xxxxxxxxxxxxxxxx/Variables/Variable.h: In instantiation of 'Variable<Type, Extentions>::Variable(Type, Args ...) [with Args = {}; Type = float; Extentions = {Forceable<float>}]':
xxxxxxxxxxxxxxxx\main.cpp:16:49: required from here
xxxxxxxxxxxxxxxx/Variables/Variable.h:22:108: error: mismatched argument pack lengths while expanding 'Extentions'
22 | Variable<Type,Extentions...>::Variable(Type initValue, Args... args) : GenericVar<Type>(), Extentions(args)...
| ^~~
Because of : "Extentions(args)..." instead of "Extentions()" in this case, I guess I think there's a solution... but I haven't found it!
I would like :
template<typename T>
using Constant = Variable<T, Immutable<T>, Forceable<T>>;
int main(int argc, char *argv[])
{
Variable<float, Forceable<float>> test2(1.2f);
Constant<float> constant(4.578f);
Variable<quint32, Forceable<int>, ChangeCheckable<int>> value(45);
}
Deeper example :
Variable<int, Forceable<int>, Boundable<int,int>, ChangeCheckable<int>, Validable<int>, RiseDefault<int, bool, Riseable> >
value3(0, nullptr, {-30,50}, nullptr, nullptr, 40, new Variable<bool, Riseable>(false,nullptr));