LMMS
Loading...
Searching...
No Matches
juce::Optional< Value > Class Template Reference

#include <juce_Optional.h>

Classes

struct  NotConstructibleFromSimilarType

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)
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)
 ~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
template<typename... Args>
Valueemplace (Args &&... args)
void swap (Optional &other) noexcept(std::is_nothrow_move_constructible< Value >::value &&detail::adlSwap::isNothrowSwappable< Value >)

Private Types

template<typename T, typename U>
using OptionalCopyConstructorEnabled = std::enable_if_t<std::is_constructible<T, const U&>::value && NotConstructibleFromSimilarType<T, U>::value>
template<typename T, typename U>
using OptionalMoveConstructorEnabled = std::enable_if_t<std::is_constructible<T, U&&>::value && NotConstructibleFromSimilarType<T, U>::value>
template<typename T, typename U>
using OptionalCopyAssignmentEnabled
template<typename T, typename U>
using OptionalMoveAssignmentEnabled

Private Member Functions

template<typename Other>
void constructFrom (Optional< Other > &other) noexcept(noexcept(Value(std::move(*other))))
template<typename Other>
void assign (Optional< Other > &other) noexcept(noexcept(std::declval< Value & >()=std::move(*other)) &&noexcept(std::declval< Optional >().constructFrom(other)))

Private Attributes

union { 
   char   placeholder 
   Value   storage 
}; 
bool valid = false

Static Private Attributes

template<typename T, typename U>
static auto notAssignableFromSimilarType

Detailed Description

template<typename Value>
class juce::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.

@tags{Core}

Member Typedef Documentation

◆ OptionalCopyAssignmentEnabled

template<typename Value>
template<typename T, typename U>
using juce::Optional< Value >::OptionalCopyAssignmentEnabled
private
Initial value:
std::enable_if_t<std::is_constructible<T, const U&>::value
&& std::is_assignable<T&, const U&>::value
static constexpr auto value
Definition juce_Optional.h:78

◆ OptionalCopyConstructorEnabled

template<typename Value>
template<typename T, typename U>
using juce::Optional< Value >::OptionalCopyConstructorEnabled = std::enable_if_t<std::is_constructible<T, const U&>::value && NotConstructibleFromSimilarType<T, U>::value>
private

◆ OptionalMoveAssignmentEnabled

template<typename Value>
template<typename T, typename U>
using juce::Optional< Value >::OptionalMoveAssignmentEnabled
private
Initial value:
std::enable_if_t<std::is_constructible<T, U>::value
&& std::is_nothrow_assignable<T&, U>::value

◆ OptionalMoveConstructorEnabled

template<typename Value>
template<typename T, typename U>
using juce::Optional< Value >::OptionalMoveConstructorEnabled = std::enable_if_t<std::is_constructible<T, U&&>::value && NotConstructibleFromSimilarType<T, U>::value>
private

Constructor & Destructor Documentation

◆ Optional() [1/7]

template<typename Value>
juce::Optional< Value >::Optional ( )
inline

◆ Optional() [2/7]

template<typename Value>
juce::Optional< Value >::Optional ( Nullopt )
inlinenoexcept

◆ 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>>
juce::Optional< Value >::Optional ( U && value)
inlinenoexcept

◆ Optional() [4/7]

template<typename Value>
juce::Optional< Value >::Optional ( Optional< Value > && other)
inlinenoexcept

◆ Optional() [5/7]

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

◆ Optional() [6/7]

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

◆ Optional() [7/7]

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

◆ ~Optional()

template<typename Value>
juce::Optional< Value >::~Optional ( )
inlinenoexcept

Member Function Documentation

◆ assign()

template<typename Value>
template<typename Other>
void juce::Optional< Value >::assign ( Optional< Other > & other)
inlineprivatenoexcept

◆ constructFrom()

template<typename Value>
template<typename Other>
void juce::Optional< Value >::constructFrom ( Optional< Other > & other)
inlineprivatenoexcept

◆ emplace()

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

◆ hasValue()

template<typename Value>
bool juce::Optional< Value >::hasValue ( ) const
inlinenoexcept

◆ operator bool()

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

◆ operator*() [1/2]

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

◆ operator*() [2/2]

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

◆ operator->() [1/2]

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

◆ operator->() [2/2]

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

◆ operator=() [1/6]

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

Maintains the strong exception safety guarantee.

◆ operator=() [2/6]

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

Maintains the strong exception safety guarantee.

◆ operator=() [3/6]

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

◆ operator=() [4/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 & juce::Optional< Value >::operator= ( Optional< Value > && other)
inlinenoexcept

◆ operator=() [5/6]

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

◆ operator=() [6/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 & juce::Optional< Value >::operator= ( U && value)
inline

◆ orFallback()

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

Like std::optional::value_or

◆ reset()

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

◆ swap()

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

Member Data Documentation

◆ [union]

union { ... } juce::Optional< Value >

◆ notAssignableFromSimilarType

template<typename Value>
template<typename T, typename U>
auto juce::Optional< Value >::notAssignableFromSimilarType
staticprivate
Initial value:
&& ! std::is_assignable<T&, Optional<U>&>::value
&& ! std::is_assignable<T&, const Optional<U>&>::value
&& ! std::is_assignable<T&, Optional<U>&&>::value
&& ! std::is_assignable<T&, const Optional<U>&&>::value
static PuglViewHint int value
Definition pugl.h:1708

◆ placeholder

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

◆ storage

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

◆ valid

template<typename Value>
bool juce::Optional< Value >::valid = false
private

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