|
Boost : |
Subject: Re: [boost] variant - off topic
From: degski (degski_at_[hidden])
Date: 2019-04-08 05:59:44
On Sun, 7 Apr 2019 at 18:44, Robert Ramey via Boost <boost_at_[hidden]>
wrote:
> template<T ...>
> struct safe_variant : public std::variant<T...> {
> // for each T static assert that is_trivially_constructible<T> == true
> };
>
> Which gets trickier. But would be cool if someone wanted to make this.
>
#include <type_traits>
#include <variant>
struct Foo {
Foo ( ) = delete;
};
template<typename... Args>
struct safe_variant : public std::variant<Args...> {
static_assert (
std::conjunction<std::is_trivially_constructible<Args>...>::value, "is not
trivially constructible" );
};
int main ( ) {
safe_variant<int, double, bool> sv1; // compiles
// safe_variant<int, double, bool, Foo> sv2; // does not compile
}
Unless I mis-understand what you mean, this does the trick.
degski
-- *Microsoft, please kill Paint3D*
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk