Using C++ std::expected<T,E> to Return either a Value or an Error

(Heavily from https://en.cppreference.com/w/cpp/utility/expected.html)

The class template std::expected provides a way to represent either of two values: an expected value of type T, or an unexpected value of type E.

std::expected is never valueless.

template< class T, class E >
class expected;

A program is ill-formed if it instantiates an std::expected with a reference type, a function type, or a specialization of std::unexpected. In addition, T must not be std::in_place_t or std::unexpect_t.