Boost logo

Boost Users :

Subject: Re: [Boost-users] boost variant is not a literal type
From: Robert Ramey (ramey_at_[hidden])
Date: 2016-01-06 17:23:44


On 1/6/16 1:03 PM, Agustín K-ballo Bergé wrote:
> On 1/6/2016 5:52 PM, Robert Ramey wrote:
>> I want to use Boost.Variant constexpr function. In order to do this it
>> has to be a literal type - which apparently it isn't. The rule for
>> being a literal type are summarized here:
>>
>> http://en.cppreference.com/w/cpp/concept/LiteralType
>>
>> a boost::variant isn't default constructable so it fails to qualify.
>
> A default constructor is not a requirement of literal type.
my mistake
>
>> Has anyone else had this problem before and managed to solve it in a
>> convenient way?
>
> Constexpr support is a complicated thing for `variant`, and it would
> require a complete reimplementation of `boost::variant`. The trickiest
> part is having a trivial destructor. For the gory details have a look at
> these articles:
>
> https://akrzemi1.wordpress.com/2012/12/13/constexpr-unions/
>
> http://talesofcpp.fusionfenix.com/post-20/eggs.variant---part-ii-the-constexpr-experience

I've read your eggs.variant and it seems exactly what I'm looking for so
I cloned. I used CMake to make and xcode project and I've got a couple
of questions:

a) It doesn't seem to specify CTest, at least my xcode project doesn't
have a "RUN_TESTS" target. I try to build the tests and I get error
messages like:

/Users/robertramey/WorkingProjects/variant/include/eggs/variant/detail/pack.hpp:22:9:
Unknown type name 'constexpr'

at line which contains "EGGS_CXX11_CONSTESPR"

which suggests that I haven't got things setup quite right.

a) Am I correct in my understanding that this will provide similar
facilities to boost variant in way which supports constexpr?

b) Anything I haven't done to run test on and use this library.

c) Is there any reason that you haven't submitted this to the Boost
Library Incubator?

Roebrt Ramey

>
>
> Also note that literal unions are over restricted, and that restricts
> the kind of member types a literal variant might have. That's CWG2096
> http://open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2096
>
> Regards,


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net