18 template<
typename TValue>
22 using TValueDeref = std::remove_reference_t<TValue>;
23 using TValueStore = std::conditional_t<
24 std::is_reference_v<TValue>,
25 std::reference_wrapper<TValueDeref>,
29 std::optional<TValueStore> inner;
37 constexpr IterValue(
const TValueDeref&
value)
noexcept(std::is_nothrow_copy_constructible_v<TValueDeref>)
38 requires (!std::is_reference_v<TValue>) : inner(
value) {}
40 constexpr IterValue(TValueDeref&&
value)
noexcept(std::is_nothrow_move_constructible_v<TValueDeref>)
41 : inner(std::forward<TValueDeref>(
value)) {}
47 : inner(std::move(o.inner)) {
53 this->inner = std::forward<decltype(o)>(o);
62 constexpr inline const TValueDeref&
value()
const {
return inner.value(); }
68 constexpr inline TValueDeref&
value() {
return inner.value(); }
74 constexpr inline const TValueDeref&
value_or(TValueDeref&& def)
const noexcept {
return inner.value_or(def); }
80 constexpr inline TValueDeref&
value_or(TValueDeref&& def)
noexcept {
return inner.value_or(def); }
86 constexpr bool has_value() const noexcept {
return inner.has_value(); }
100 return std::optional<TValueStore>(std::move(this->inner));
105 constexpr operator std::optional<TValueStore>() noexcept {
return toStdOptional(); }
113 template<
typename TOutValue, std::invocable<TValueDeref&&> TMapFn>
114 requires (!std::is_reference_v<TValue>)
117 return mapFn(std::forward<TValueDeref>(
value()));
126 template<
typename TOutValue, std::invocable<TValue> TMapFn>
127 requires std::is_reference_v<TValue>
130 return mapFn(this->
value());
Container that is used to pass elements through CXXIter's iterator pipelines.
constexpr bool has_value() const noexcept
Get whether this optional IteratorValue contains a value.
constexpr std::optional< TValueStore > toStdOptional() noexcept
Convert this IterValue to a std::optional<> on the owned (no-reference) type.
constexpr void swap(IterValue< TValue > &o) noexcept
Swap the values within this and another IterValue container.
constexpr const TValueDeref & value_or(TValueDeref &&def) const noexcept
Get the contained value, or alternatively the given def if none is present.
constexpr IterValue(TValue value) noexcept
constexpr IterValue(IterValue &&o) noexcept(std::is_nothrow_move_constructible_v< TValueDeref >)
constexpr IterValue< TOutValue > map(TMapFn mapFn)
Map this IterValue's contained value (if any) to the requested new TOutValue type,...
constexpr IterValue< TOutValue > map(TMapFn mapFn)
Map this IterValue's contained value (if any) to the requested new TOutValue type,...
constexpr TValueDeref & value_or(TValueDeref &&def) noexcept
Get the contained value, or alternatively the given def if none is present.
constexpr IterValue(TValueDeref &&value) noexcept(std::is_nothrow_move_constructible_v< TValueDeref >)
constexpr TValueDeref & value()
Get the contained value (if any).
constexpr IterValue() noexcept
constexpr IterValue & operator=(IterValue &&o)=default
constexpr auto & operator=(TValueDeref &&o)
constexpr const TValueDeref & value() const
Get the contained value (if any).
constexpr IterValue(const TValueDeref &value) noexcept(std::is_nothrow_copy_constructible_v< TValueDeref >)