AK: Add Optional<T>(const U&)

This replaces Optional<T>(U&&) which clang-tidy complained may hide the
regular copy and move constructors. That's a good point, clang-tidy,
and I appreciate you pointing that out!
This commit is contained in:
Andreas Kling 2019-08-08 18:34:59 +02:00
parent 533b5c0adc
commit 865a1b913c
Notes: sideshowbarker 2024-07-19 12:48:58 +09:00

View file

@ -10,15 +10,22 @@ public:
Optional() {}
RETURN_TYPESTATE(unknown)
Optional(T&& value)
Optional(const T& value)
: m_has_value(true)
{
new (&m_storage) T(move(value));
new (&m_storage) T(value);
}
template<typename U>
RETURN_TYPESTATE(unknown)
Optional(U&& value)
Optional(const U& value)
: m_has_value(true)
{
new (&m_storage) T(value);
}
RETURN_TYPESTATE(unknown)
Optional(T&& value)
: m_has_value(true)
{
new (&m_storage) T(move(value));