JUCE: Optional< Value > Class Template Reference

JUCE

Public Member Functions | List of all members
Optional< Value > Class Template Reference
juce_core » containers

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)
Optional & | operator= (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>>
Optional & | operator= (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)>>
Optional & | operator= (U &&value)
Optional & | operator= (const Optional &other)
| Maintains the strong exception safety guarantee. More...
template<typename Other , typename = OptionalMoveAssignmentEnabled<Value, Other>>
Optional & | operator= (Optional< Other > &&other) noexcept(noexcept(std::declval< Optional >().assign(other)))
template<typename Other , typename = OptionalCopyAssignmentEnabled<Value, Other>>
Optional & | operator= (const Optional< Other > &other)
| Maintains the strong exception safety guarantee. More...
| ~Optional () noexcept
Value * | operator-> () noexcept
const Value * | operator-> () const noexcept
Value & | operator* () noexcept
const Value & | operator* () 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. More...
template<typename... Args>
Value & | emplace (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]

template<typename Value >

Optional< Value >::Optional | ( |  | ) |

## ◆ Optional() [2/7]

template<typename Value >

Optional< Value >::Optional | ( | Nullopt |  | ) |
| noexcept

## ◆ 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

## ◆ Optional() [4/7]

template<typename Value >

Optional< Value >::Optional | ( | Optional< Value > && | other | ) |
| noexcept

## ◆ Optional() [5/7]

template<typename Value >

Optional< Value >::Optional | ( | const Optional< Value > & | other | ) |

## ◆ Optional() [6/7]

template<typename Value >
template<typename Other , typename = OptionalMoveConstructorEnabled<Value, Other>>

Optional< Value >::Optional | ( | Optional< Other > && | other | ) |
| noexcept

## ◆ 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 gl::reset.

## Member Function Documentation

## ◆ operator=() [1/6]

template<typename Value >

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

References gl::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

## ◆ 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 gl::value.

## ◆ operator=() [4/6]

template<typename Value >

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

Maintains the strong exception safety guarantee.

References StandardApplicationCommandIDs::copy.

## ◆ operator=() [5/6]

template<typename Value >
template<typename Other , typename = OptionalMoveAssignmentEnabled<Value, Other>>

Optional & Optional< Value >::operator= | ( | Optional< Other > && | other | ) |
| noexcept

## ◆ 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 StandardApplicationCommandIDs::copy.

## ◆ operator->() [1/2]

template<typename Value >

Value * Optional< Value >::operator-> | ( |  | ) |
| noexcept

## ◆ operator->() [2/2]

template<typename Value >

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

## ◆ operator*() [1/2]

template<typename Value >

Value & Optional< Value >::operator* | ( |  | ) |
| noexcept

## ◆ operator*() [2/2]

template<typename Value >

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

## ◆ operator bool()

template<typename Value >

Optional< Value >::operator bool | ( |  | ) | const
| explicitnoexcept

## ◆ hasValue()

template<typename Value >

bool Optional< Value >::hasValue | ( |  | ) | const
| noexcept

Referenced by operator!=(), operator<(), operator<=(), operator==(), operator>(), and operator>=().

## ◆ reset()

template<typename Value >

void Optional< Value >::reset | ( |  | ) |

References operator*().

## ◆ 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 gl::reset.

## ◆ 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:

- juce_Optional.h