"ScL Feature"/
SCL Feature 0.0.1
C++20 composable proxy wrapper with pluggable executor strategy
Loading...
Searching...
No Matches
plain.h
1#pragma once
2
3#include <concepts>
4#include <functional>
5#include <utility>
6
7#include <scl/utility/type_traits/forward_like.h>
8
9#define SCL_EXECUTOR_CONSTRUCTOR_FOR_SELF_PROTOTYPE(cv_ref) \
10 constexpr explicit plain(self_type cv_ref other) noexcept( \
11 ::std::is_nothrow_constructible_v<value_type, value_type cv_ref>) \
12 requires(::std::constructible_from<value_type, value_type cv_ref>) \
13 : m_value{::std::forward<value_type cv_ref>(other.m_value)} \
14 {}
15
21#define SCL_EXECUTOR_CONSTRUCTOR_FOR_SELF \
22 SCL_EXECUTOR_CONSTRUCTOR_FOR_SELF_PROTOTYPE(&) \
23 SCL_EXECUTOR_CONSTRUCTOR_FOR_SELF_PROTOTYPE(const &) \
24 SCL_EXECUTOR_CONSTRUCTOR_FOR_SELF_PROTOTYPE(volatile &) \
25 SCL_EXECUTOR_CONSTRUCTOR_FOR_SELF_PROTOTYPE(const volatile &) \
26 SCL_EXECUTOR_CONSTRUCTOR_FOR_SELF_PROTOTYPE(&&) \
27 SCL_EXECUTOR_CONSTRUCTOR_FOR_SELF_PROTOTYPE(const &&) \
28 SCL_EXECUTOR_CONSTRUCTOR_FOR_SELF_PROTOTYPE(volatile &&) \
29 SCL_EXECUTOR_CONSTRUCTOR_FOR_SELF_PROTOTYPE(const volatile &&)
30
31namespace scl::feature::inplace
32{
45 // NOLINTBEGIN(cppcoreguidelines-special-member-functions, cppcoreguidelines-missing-std-forward)
46 template <typename Value>
47 class plain
48 {
49 using self_type = plain<Value>;
50
51 public:
52 using value_type = Value;
53
54 public:
55 template <typename... Args>
56 constexpr explicit plain(Args &&... args)
57 : m_value{::std::forward<Args>(args)...}
58 {}
59
60 SCL_EXECUTOR_CONSTRUCTOR_FOR_SELF
61
62 public:
63 template <typename Self, typename Func, typename... Args>
64 static constexpr decltype(auto) execute(Self && self, Func && func, Args &&... args)
65 requires(::std::same_as<::std::remove_cvref_t<Self>, self_type> && ::std::invocable<Func, Args && ...>)
66 {
67 return ::std::invoke(::std::forward<Func>(func), ::std::forward<Args>(args)...);
68 }
69
70 template <typename Self>
71 static constexpr decltype(auto) value(Self && self)
72 requires ::std::same_as<::std::remove_cvref_t<Self>, self_type>
73 {
74 return ::scl::forward_like<Self>(self.m_value);
75 }
76
77 private:
78 value_type m_value;
79 };
80 // NOLINTEND(cppcoreguidelines-special-member-functions, cppcoreguidelines-missing-std-forward)
81} // namespace scl::feature::inplace
82
83#undef SCL_EXECUTOR_CONSTRUCTOR_FOR_SELF
84#undef SCL_EXECUTOR_CONSTRUCTOR_FOR_SELF_PROTOTYPE