variant: change the method to check for suitable payload type

the reason is also to enable usage as metafunction,
to disable specialisations for some type which could
never live within a variant record in question
This commit is contained in:
Fischlurch 2016-03-24 17:29:26 +01:00
parent 4a0ad73ade
commit 4e6fd86c8d

View file

@ -118,33 +118,34 @@ namespace lib {
template<typename X, typename TYPES>
struct CanBuildFrom<X, Node<X, TYPES>>
: std::true_type
{
using Type = X;
};
template<typename X, typename TYPES>
struct CanBuildFrom<const X, Node<X, TYPES>>
: std::true_type
{
using Type = X;
};
template<typename TYPES, size_t len>
struct CanBuildFrom<const char [len], Node<string, TYPES>> ///< esp. allow to build string from char literal
: std::true_type
{
using Type = string;
};
template<typename X, typename T,typename TYPES>
struct CanBuildFrom<X, Node<T, TYPES>>
{
using Type = typename CanBuildFrom<X,TYPES>::Type;
};
: CanBuildFrom<X,TYPES>
{ };
template<typename X>
struct CanBuildFrom<X, NullType>
{
static_assert (0 > sizeof(X), "No type in Typelist can be built from the given argument");
};
: std::false_type
{ };
@ -398,6 +399,8 @@ namespace lib {
template<typename X>
Variant(X&& x)
{
static_assert (variant::CanBuildFrom<X, TYPES>(), "No type in Typelist can be built from the given argument");
using StorageType = typename variant::CanBuildFrom<X, TYPES>::Type;
new(storage_) Buff<StorageType> (forward<X>(x));