Simple-Utility v2.3.1
Loading...
Searching...
No Matches
fwd_value.hpp
Go to the documentation of this file.
1// Copyright Dominic Koepke 2019 - 2023.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at
4// https://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef SL_UTILITY_NULLABLES_FWD_VALUE_HPP
7#define SL_UTILITY_NULLABLES_FWD_VALUE_HPP
8
9#pragma once
10
13
14namespace sl::nullables::detail
15{
16 template <input_nullable TInputNullable, std::invocable<dereference_result_t<TInputNullable>> TFunc>
17 constexpr void fwd_value(TInputNullable&& inputNullable, TFunc&& func)
18 {
19 if (inputNullable != null_v<TInputNullable>)
20 {
21 std::invoke(std::forward<TFunc>(func), unwrap(std::forward<TInputNullable>(inputNullable)));
22 }
23 }
24
25 class fwd_value_caller_fn
26 {
27 public:
28 template <input_nullable TInputNullable, std::invocable<dereference_result_t<TInputNullable>> TFunc>
29 constexpr void operator ()
30 (
31 TInputNullable&& inputNullable,
32 TFunc&& func
33 ) const
34 noexcept(noexcept(fwd_value(std::declval<TInputNullable>(), std::declval<TFunc>())))
35 {
37 std::forward<TInputNullable>(inputNullable),
38 std::forward<TFunc>(func)
39 );
40 }
41 };
42}
43
44namespace sl::nullables
45{
68 inline constexpr auto fwd_value = []<class Fn>(Fn&& fn) noexcept(std::is_nothrow_constructible_v<std::remove_cvref_t<Fn>, Fn>)
69 {
70 return Algorithm{functional::bind_back(detail::fwd_value_caller_fn{}, std::forward<Fn>(fn))};
71 };
72
74}
75
76#endif
The core algorithm helper, which executes the held operation when used as the right-hand-side of oper...
Definition: base.hpp:216
constexpr auto bind_back
Helper function, which generates a forwarding call wrapper for the given function and curries the par...
Definition: bind_back.hpp:100
constexpr auto fwd_value
Passes the value of the input_nullable to the function if it's not equal to its null-object.
Definition: fwd_value.hpp:68
constexpr detail::unwrap_fn unwrap
Retrieves the value of the given input_nullable.
Definition: base.hpp:160
Definition: adapter.hpp:19