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.
I am looking for C++14 optional drop-in which I can use in
constexprcontexts. From the Readme it seems to fit my needs, because you state this implementation provides a LiteralType in that case. I tried to compilewith
std=c++14two 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)optionaltrivial for trivially destructible typesT. This can be achieved by inheriting from a base class and using a template specialization.constexprTo make the type usuable in constexpr contexts:
storage_tis not constexpr, sononstd::optionalwith 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.