$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [boost] variant - off topic
From: Robert Ramey (ramey_at_[hidden])
Date: 2019-04-08 06:29:58
On 4/7/19 10:59 PM, degski via Boost wrote:
> 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
>
LOL - Looks good to me! So now we have std::variant that is guaranteed
to have a valid state with no double buffer BS and no extra overhead.
I'll be curious to hear what otherothers have to say about this.
Robert Ramey