template<typename ValueType>
class observable::value< ValueType >
Get notified when a value-type changes.
When setting a new value, if the new value is different than the existing one, any subscribed observers will be notified.
Equality will be checked using std::equal_to<ValueType>
if the ValueType is EqualityComparable, else all values will be assumed to be unequal.
- Warning
- None of the methods in this class can be safely called concurrently.
- Template Parameters
-
ValueType | The value-type that will be stored inside the observable. This type will need to be at least movable. |
|
| value ()=default |
| Create a default-constructed observable value. More...
|
|
| value (ValueType initial_value) noexcept(std::is_nothrow_move_constructible< ValueType >::value) |
| Create an initialized observable value. More...
|
|
template<typename EqualityComparator > |
| value (ValueType initial_value, EqualityComparator equal) noexcept(std::is_nothrow_move_constructible< ValueType >::value &&std::is_nothrow_move_constructible< EqualityComparator >::value) |
| Create an initialized observable value. More...
|
|
template<typename UpdaterType > |
| value (std::unique_ptr< UpdaterType > &&ud) |
| Create an initialized value that will be updated by the provided value_updater. More...
|
|
| operator ValueType const & () const noexcept |
| Convert the observable value to its stored value type. More...
|
|
auto | get () const noexcept -> ValueType const & |
| Retrieve the stored value. More...
|
|
template<typename Callable > |
auto | subscribe (Callable &&observer) const |
| Subscribe to changes to the observable value. More...
|
|
template<typename Callable > |
auto | subscribe_and_call (Callable &&observer) const |
| Subscribe to changes to the observable value and also call the observer callback immediately with the current value. More...
|
|
void | set (ValueType new_value) |
| Set a new value, possibly notifying any subscribed observers. More...
|
|
auto | operator= (ValueType new_value) -> value & |
| Set a new value. More...
|
|
| ~value () |
| Destructor. More...
|
|
| value (value< ValueType > const &)=delete |
| Observable values are not copy-constructible. More...
|
|
auto | operator= (value< ValueType > const &) -> value< ValueType > &=delete |
| Observable values are not copy-assignable. More...
|
|
template<typename = std::enable_if_t<std::is_move_constructible<ValueType>::value>> |
| value (value< ValueType > &&other) noexcept(std::is_nothrow_move_constructible< ValueType >::value) |
| Observable values are move-constructible. More...
|
|
template<typename = std::enable_if_t<std::is_move_assignable<ValueType>::value>> |
auto | operator= (value< ValueType > &&other) noexcept(std::is_nothrow_move_assignable< ValueType >::value) -> value< ValueType > & |
| Observable values are move-assignable. More...
|
|
template<typename ValueType >
template<typename EqualityComparator >
observable::value< ValueType >::value |
( |
ValueType |
initial_value, |
|
|
EqualityComparator |
equal |
|
) |
| |
|
inlinenoexcept |
Create an initialized observable value.
- Parameters
-
initial_value | The observable's initial value. |
equal | A functor to be used for comparing values. The functor must have a signature compatible with the one below: |
bool(ValueType const &, ValueType const &)
The comparator must return true if both of its parameters are equal.
template<typename ValueType >
template<typename Callable >
auto observable::value< ValueType >::subscribe_and_call |
( |
Callable && |
observer | ) |
const |
|
inline |
Subscribe to changes to the observable value and also call the observer callback immediately with the current value.
If the observer throws an exception during the initial call, it will not be subscribed.
- Note
- The observer is not subscribed during the initial call.
- Parameters
-
[in] | observer | A callable that will be called whenever the value changes. The observer must satisfy the Callable concept. |
- Template Parameters
-
Callable | A callable taking no parameters or a callable taking one parameter that will be called with the new value: |
void()
– will be called when the value changes but will not receive the new value.
void(T const &)
or void(T)
– will be called with the new value. The expression T { value.get() }
must be correct.
- See also
- subscribe()