20class move_only_function<R(Args...)> {
23 static constexpr bool is_callable() {
27 move_only_function() =
default;
32 template<
typename F, HALCHECK_REQUIRE(is_callable<lib::decay_t<F>>())>
33 move_only_function(F &&f)
41 explicit move_only_function(lib::in_place_type_t<F>, Args2... args)
53 move_only_function &operator=(
std::nullptr_t)
noexcept { _impl.reset(); }
55 template<
typename F, HALCHECK_REQUIRE(is_callable<lib::decay_t<F>>())>
56 move_only_function &operator=(F &&func)
noexcept {
62 void swap(move_only_function &other)
noexcept {
std::swap(_impl, other._impl); }
64 explicit operator bool()
const noexcept {
return bool(_impl); }
68 virtual ~base() =
default;
69 virtual R operator()(Args...) = 0;
73 struct derived : base {
74 template<
typename... Args2>
76 R operator()(Args... args)
override {
return lib::invoke(std::move(func),
std::forward<Args>(args)...); }
89class move_only_function<R(Args...) const> {
92 static constexpr bool is_callable() {
96 move_only_function() =
default;
101 template<
typename F, HALCHECK_REQUIRE(is_callable<lib::decay_t<F>>())>
102 move_only_function(F &&f)
110 explicit move_only_function(lib::in_place_type_t<F>, Args2... args)
122 move_only_function &operator=(
std::nullptr_t)
noexcept { _impl.reset(); }
124 template<
typename F, HALCHECK_REQUIRE(is_callable<lib::decay_t<F>>())>
125 move_only_function &operator=(F &&func)
noexcept {
131 void swap(move_only_function &other)
noexcept {
std::swap(_impl, other._impl); }
133 explicit operator bool()
const noexcept {
return bool(_impl); }
137 virtual ~base() =
default;
138 virtual R operator()(Args...)
const = 0;
142 struct derived : base {
143 template<
typename... Args2>
145 R operator()(Args... args)
const override {
return lib::invoke(std::move(func),
std::forward<Args>(args)...); }
158class move_only_function<R(Args...) const &> {
161 static constexpr bool is_callable() {
165 move_only_function() =
default;
170 template<
typename F, HALCHECK_REQUIRE(is_callable<lib::decay_t<F>>())>
171 move_only_function(F &&f)
179 explicit move_only_function(lib::in_place_type_t<F>, Args2... args)
191 move_only_function &operator=(
std::nullptr_t)
noexcept { _impl.reset(); }
193 template<
typename F, HALCHECK_REQUIRE(is_callable<lib::decay_t<F>>())>
194 move_only_function &operator=(F &&func)
noexcept {
200 void swap(move_only_function &other)
noexcept {
std::swap(_impl, other._impl); }
202 explicit operator bool()
const noexcept {
return bool(_impl); }
206 virtual ~base() =
default;
207 virtual R operator()(Args...)
const & = 0;
211 struct derived : base {
212 template<
typename... Args2>
214 R operator()(Args... args)
const &
override {
return lib::invoke(std::move(func),
std::forward<Args>(args)...); }
227class move_only_function<R(Args...) &> {
230 static constexpr bool is_callable() {
234 move_only_function() =
default;
239 template<
typename F, HALCHECK_REQUIRE(is_callable<lib::decay_t<F>>())>
240 move_only_function(F &&f)
248 explicit move_only_function(lib::in_place_type_t<F>, Args2... args)
260 move_only_function &operator=(
std::nullptr_t)
noexcept { _impl.reset(); }
262 template<
typename F, HALCHECK_REQUIRE(is_callable<lib::decay_t<F>>())>
263 move_only_function &operator=(F &&func)
noexcept {
269 void swap(move_only_function &other)
noexcept {
std::swap(_impl, other._impl); }
271 explicit operator bool()
const noexcept {
return bool(_impl); }
275 virtual ~base() =
default;
276 virtual R operator()(Args...) & = 0;
280 struct derived : base {
281 template<
typename... Args2>
283 R operator()(Args... args) &
override {
return lib::invoke(std::move(func),
std::forward<Args>(args)...); }
296class move_only_function<R(Args...) const &&> {
299 static constexpr bool is_callable() {
303 move_only_function() =
default;
308 template<
typename F, HALCHECK_REQUIRE(is_callable<lib::decay_t<F>>())>
309 move_only_function(F &&f)
317 explicit move_only_function(lib::in_place_type_t<F>, Args2... args)
329 move_only_function &operator=(
std::nullptr_t)
noexcept { _impl.reset(); }
331 template<
typename F, HALCHECK_REQUIRE(is_callable<lib::decay_t<F>>())>
332 move_only_function &operator=(F &&func)
noexcept {
336 R operator()(Args... args)
const && {
return std::move(*_impl)(
std::forward<Args>(args)...); }
338 void swap(move_only_function &other)
noexcept {
std::swap(_impl, other._impl); }
340 explicit operator bool()
const noexcept {
return bool(_impl); }
344 virtual ~base() =
default;
345 virtual R operator()(Args...)
const & = 0;
349 struct derived : base {
350 template<
typename... Args2>
352 R operator()(Args... args)
const &&
override {
return lib::invoke(std::move(func),
std::forward<Args>(args)...); }
365class move_only_function<R(Args...) &&> {
368 static constexpr bool is_callable() {
372 move_only_function() =
default;
377 template<
typename F, HALCHECK_REQUIRE(is_callable<lib::decay_t<F>>())>
378 move_only_function(F &&f)
386 explicit move_only_function(lib::in_place_type_t<F>, Args2... args)
398 move_only_function &operator=(
std::nullptr_t)
noexcept { _impl.reset(); }
400 template<
typename F, HALCHECK_REQUIRE(is_callable<lib::decay_t<F>>())>
401 move_only_function &operator=(F &&func)
noexcept {
405 R operator()(Args... args) && {
return std::move(*_impl)(
std::forward<Args>(args)...); }
407 void swap(move_only_function &other)
noexcept {
std::swap(_impl, other._impl); }
409 explicit operator bool()
const noexcept {
return bool(_impl); }
413 virtual ~base() =
default;
414 virtual R operator()(Args...) && = 0;
418 struct derived : base {
419 template<
typename... Args2>
421 R operator()(Args... args) &&
override {
return lib::invoke(std::move(func),
std::forward<Args>(args)...); }
#define HALCHECK_REQUIRE(...)
Expands to a template argument that is only valid if the given argument evaluates to true.
Definition type_traits.hpp:24