arg_router  1.4.0
C++ command line argument parsing and routing
multi_stage_value.hpp
1 // Copyright (C) 2022-2023 by Camden Mannett.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
4 
5 #pragma once
6 
7 #include "arg_router/policy/policy.hpp"
8 
9 #include <functional>
10 #include <optional>
11 
12 namespace arg_router::policy
13 {
27 template <typename ResultType, typename ValueType>
29 {
30 public:
32  using merge_fn = std::function<void(std::optional<ResultType>&, ValueType&&)>;
33 
38  constexpr explicit multi_stage_value(merge_fn fn) noexcept : fn_{std::move(fn)} {}
39 
45  constexpr void merge(std::optional<ResultType>& result, ValueType&& value) const
46  {
47  fn_(result, std::forward<ValueType>(value));
48  }
49 
50 private:
51  merge_fn fn_;
52 };
53 
54 template <typename ResultType, typename ValueType>
55 struct is_policy<multi_stage_value<ResultType, ValueType>> : std::true_type {
56 };
57 
62 template <typename T>
64 private:
65  template <typename... Ts>
66  constexpr static std::true_type test(const multi_stage_value<Ts...>*);
67 
68  constexpr static std::false_type test(...);
69 
70 public:
71  // NOLINTNEXTLINE(hicpp-vararg)
72  constexpr static bool value = decltype(test(std::declval<T*>()))::value;
73 };
74 
79 template <typename T>
81 } // namespace arg_router::policy
constexpr multi_stage_value(merge_fn fn) noexcept
std::function< void(std::optional< ResultType > &, ValueType &&)> merge_fn
constexpr void merge(std::optional< ResultType > &result, ValueType &&value) const
constexpr bool has_multi_stage_value_v