Skip to content

nonstd::optional is not a literal type #19

@maikel

Description

@maikel

I am looking for C++14 optional drop-in which I can use in constexpr contexts. From the Readme it seems to fit my needs, because you state this implementation provides a LiteralType in that case. I tried to compile

int main()
{
  constexpr nonstd::optional<int> o = 2;
}

with std=c++14 two different compilers (gcc-8 and clang-5) and both failed to compile the code.

While trying to fix the issue with custom patches I encountered following problems:

To make the type satisfy std::is_literal_type (deprecated, I know)

  • I had to make the destructor of optional trivial for trivially destructible types T. This can be achieved by inheriting from a base class and using a template specialization.
  • I had to mark at least on constructor of storage constexpr

To make the type usuable in constexpr contexts:

  • placement new in storage_t is not constexpr, so nonstd::optional with this storage implementation is not going to be usable in constexpr contexts.

Did i misunderstand something terribly wrong and/or do you think it would be worthwhile to provide some patches to target the above points.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions