From 4e6fd86c8d0b41f2694d6b014943caa5aad1d416 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 24 Mar 2016 17:29:26 +0100 Subject: [PATCH] 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 --- src/lib/variant.hpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/lib/variant.hpp b/src/lib/variant.hpp index ad34f0f22..05426b25e 100644 --- a/src/lib/variant.hpp +++ b/src/lib/variant.hpp @@ -118,33 +118,34 @@ namespace lib { template struct CanBuildFrom> + : std::true_type { using Type = X; }; template struct CanBuildFrom> + : std::true_type { using Type = X; }; template struct CanBuildFrom> ///< esp. allow to build string from char literal + : std::true_type { using Type = string; }; template struct CanBuildFrom> - { - using Type = typename CanBuildFrom::Type; - }; + : CanBuildFrom + { }; template struct CanBuildFrom - { - 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 Variant(X&& x) { + static_assert (variant::CanBuildFrom(), "No type in Typelist can be built from the given argument"); + using StorageType = typename variant::CanBuildFrom::Type; new(storage_) Buff (forward(x));