because "if constexpr(...)" is a c++17 feature which i'm using it to allow usage of nl::unexpected() to return a nl::expected<nl::monostate, E> to nl::expected<T, E> in this copy constructor
template<class U>
expected(const expected<U, E>& other) : _has_value(other.has_value()) // a copy constructor
{
if (_has_value)
{
if constexpr (std::is_same<U, monostate>::value) // it checks if U == monostate
{
// makes an empty instance of "T"
}
else if constexpr (std::is_same<U, T>::value) // it checks if U == T
{
// otherwise copies "other._value" into _value
}
else
{
static_assert(
not std::is_same<U, T>::value, "no available conversion between the provided value types");
}
}
else
{
new (std::addressof(_error)) E(other.error());
}
}
template<class E>
expected<monostate, E> unexpected(const E& e) // then this can covert <monostate, E> to <T, E> fine because of this copy constructor
{
return expected<monostate, E>(e);
}
// example usage
nl::expected<int, std::string> meow = nl::unexpected("error");
but i could take a different approach and make 2 copy constructor one that explicitly takes
expected(const expected<monostate, E>& other)
and another
expected(const expected& other)
I was also using "std::is_same_v" which is a c++17 feature instead "std::is_same<>::value" but i made a commit and changed it. it now compiles with c++14 but with c++17 extensions