JUCE
Loading...
Searching...
No Matches
Optional< Value > Class Template Reference

A simple optional type. More...

#include <juce_Optional.h>

Public Member Functions

 Optional ()
 Optional (Nullopt) noexcept
template<typename U = Value, typename = std::enable_if_t<std::is_constructible<Value, U&&>::value && ! std::is_same<std::decay_t<U>, Optional>::value>>
 Optional (U &&value) noexcept(noexcept(Value(std::forward< U >(value))))
 Optional (Optional &&other) noexcept(noexcept(std::declval< Optional >().constructFrom(other)))
 Optional (const Optional &other)
template<typename Other, typename = OptionalMoveConstructorEnabled<Value, Other>>
 Optional (Optional< Other > &&other) noexcept(noexcept(std::declval< Optional >().constructFrom(other)))
template<typename Other, typename = OptionalCopyConstructorEnabled<Value, Other>>
 Optional (const Optional< Other > &other)
Optionaloperator= (Nullopt) noexcept
template<typename U = Value, typename = std::enable_if_t<std::is_nothrow_move_constructible<U>::value && std::is_nothrow_move_assignable<U>::value>>
Optionaloperator= (Optional &&other) noexcept(noexcept(std::declval< Optional >().assign(std::declval< Optional & >())))
template<typename U = Value, typename = std::enable_if_t<! std::is_same<std::decay_t<U>, Optional>::value && std::is_constructible<Value, U>::value && std::is_assignable<Value&, U>::value && (! std::is_scalar<Value>::value || ! std::is_same<std::decay_t<U>, Value>::value)>>
Optionaloperator= (U &&value)
Optionaloperator= (const Optional &other)
 Maintains the strong exception safety guarantee.
template<typename Other, typename = OptionalMoveAssignmentEnabled<Value, Other>>
Optionaloperator= (Optional< Other > &&other) noexcept(noexcept(std::declval< Optional >().assign(other)))
template<typename Other, typename = OptionalCopyAssignmentEnabled<Value, Other>>
Optionaloperator= (const Optional< Other > &other)
 Maintains the strong exception safety guarantee.
 ~Optional () noexcept
Valueoperator-> () noexcept
const Valueoperator-> () const noexcept
Valueoperator* () noexcept
const Valueoperator* () const noexcept
 operator bool () const noexcept
bool hasValue () const noexcept
void reset ()
template<typename U>
Value orFallback (U &&fallback) const
 Like std::optional::value_or.
template<typename... Args>
Valueemplace (Args &&... args)
void swap (Optional &other) noexcept(std::is_nothrow_move_constructible< Value >::value &&detail::adlSwap::isNothrowSwappable< Value >)

Detailed Description

template<typename Value>
class Optional< Value >

A simple optional type.

Has similar (not necessarily identical!) semantics to std::optional.

This is intended to stand-in for std::optional while JUCE's minimum supported language standard is lower than C++17. When the minimum language standard moves to C++17, this class will probably be deprecated, in much the same way that juce::ScopedPointer was deprecated in favour of std::unique_ptr after C++11.

This isn't really intended to be used by JUCE clients. Instead, it's to be used internally in JUCE code, with an API close-enough to std::optional that the types can be swapped with fairly minor disruption at some point in the future, but without breaking any public APIs.

Constructor & Destructor Documentation

◆ Optional() [1/7]

◆ Optional() [2/7]

template<typename Value>
Optional< Value >::Optional ( Nullopt )
noexcept

References placeholder.

◆ Optional() [3/7]

template<typename Value>
template<typename U = Value, typename = std::enable_if_t<std::is_constructible<Value, U&&>::value && ! std::is_same<std::decay_t<U>, Optional>::value>>
Optional< Value >::Optional ( U && value)
noexcept

References storage.

◆ Optional() [4/7]

template<typename Value>
Optional< Value >::Optional ( Optional< Value > && other)
noexcept

References Optional(), and placeholder.

◆ Optional() [5/7]

template<typename Value>
Optional< Value >::Optional ( const Optional< Value > & other)

References Optional(), placeholder, and storage.

◆ Optional() [6/7]

template<typename Value>
template<typename Other, typename = OptionalMoveConstructorEnabled<Value, Other>>
Optional< Value >::Optional ( Optional< Other > && other)
noexcept

References Optional(), and placeholder.

◆ Optional() [7/7]

template<typename Value>
template<typename Other, typename = OptionalCopyConstructorEnabled<Value, Other>>
Optional< Value >::Optional ( const Optional< Other > & other)

◆ ~Optional()

template<typename Value>
Optional< Value >::~Optional ( )
noexcept

References reset().

Member Function Documentation

◆ operator=() [1/6]

template<typename Value>
Optional & Optional< Value >::operator= ( Nullopt )
noexcept

References Optional(), and reset().

◆ operator=() [2/6]

template<typename Value>
template<typename U = Value, typename = std::enable_if_t<std::is_nothrow_move_constructible<U>::value && std::is_nothrow_move_assignable<U>::value>>
Optional & Optional< Value >::operator= ( Optional< Value > && other)
noexcept

References Optional().

◆ operator=() [3/6]

template<typename Value>
template<typename U = Value, typename = std::enable_if_t<! std::is_same<std::decay_t<U>, Optional>::value && std::is_constructible<Value, U>::value && std::is_assignable<Value&, U>::value && (! std::is_scalar<Value>::value || ! std::is_same<std::decay_t<U>, Value>::value)>>
Optional & Optional< Value >::operator= ( U && value)

References Optional(), and storage.

◆ operator=() [4/6]

template<typename Value>
Optional & Optional< Value >::operator= ( const Optional< Value > & other)

Maintains the strong exception safety guarantee.

References Optional().

◆ operator=() [5/6]

template<typename Value>
template<typename Other, typename = OptionalMoveAssignmentEnabled<Value, Other>>
Optional & Optional< Value >::operator= ( Optional< Other > && other)
noexcept

References Optional().

◆ operator=() [6/6]

template<typename Value>
template<typename Other, typename = OptionalCopyAssignmentEnabled<Value, Other>>
Optional & Optional< Value >::operator= ( const Optional< Other > & other)

Maintains the strong exception safety guarantee.

References Optional().

◆ operator->() [1/2]

template<typename Value>
Value * Optional< Value >::operator-> ( )
noexcept

References storage.

Referenced by operator*(), and operator*().

◆ operator->() [2/2]

template<typename Value>
const Value * Optional< Value >::operator-> ( ) const
noexcept

References storage.

◆ operator*() [1/2]

template<typename Value>
Value & Optional< Value >::operator* ( )
noexcept

References operator->().

◆ operator*() [2/2]

template<typename Value>
const Value & Optional< Value >::operator* ( ) const
noexcept

References operator->().

◆ operator bool()

template<typename Value>
Optional< Value >::operator bool ( ) const
explicitnoexcept

◆ hasValue()

◆ reset()

template<typename Value>
void Optional< Value >::reset ( )

References operator*().

Referenced by emplace(), operator=(), and ~Optional().

◆ orFallback()

template<typename Value>
template<typename U>
Value Optional< Value >::orFallback ( U && fallback) const

Like std::optional::value_or.

◆ emplace()

template<typename Value>
template<typename... Args>
Value & Optional< Value >::emplace ( Args &&... args)

References reset(), and storage.

◆ swap()

template<typename Value>
void Optional< Value >::swap ( Optional< Value > & other)
noexcept

Member Data Documentation

◆ placeholder

template<typename Value>
char Optional< Value >::placeholder

◆ storage

template<typename Value>
Value Optional< Value >::storage

The documentation for this class was generated from the following file: