chromium / subspace

A concept-centered standard library for C++20, enabling safer and more reliable products and a more modern feel for C++ code.; Also home of Subdoc the code-documentation generator.
https://suslib.cc
Apache License 2.0
89 stars 15 forks source link

Option<T> constructors cause extra never-value constructions of T #371

Closed danakj closed 1 year ago

danakj commented 1 year ago

There's a TODO in Option copy ctor about this.

  constexpr Option(const Option& o) noexcept
  {
    // TODO: This constructed a None value then destroys it and constructs a
    // Some value. Optimize.
    if (o.t_.state() == Some)
      t_.construct_from_none(copy_to_storage(o.t_.val()));
  }

The copy/move constructors are not using initializers to set the inner value, they are doing it in the body after initializing to None.