Skip to content

emplacing optional<const X> #69

@atorstling

Description

@atorstling

Hello!

Thank you for a great library. I've been using it with great pleasure. Today I found an interesting deviation from how std::optional works, and I was wondering if it's on purpose or not: std::optional<const X> allows emplacing with a new value, whereas nonstd::optional<const X> seemingly does not.

This snippet fails with what I think is trying to placement-new into const memory:

  nonstd::optional<const int> nonstd_opt;
  nonstd_opt.emplace(0);

Godbolt link: https://godbolt.org/z/r46fccxEj

Thank you for your consideration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions