Simple-Utility v2.3.1
Loading...
Searching...
No Matches
Disjunction.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 SIMPLE_UTILITY_FUNCTIONAL_MIXINS_DISJUNCTION_HPP
7#define SIMPLE_UTILITY_FUNCTIONAL_MIXINS_DISJUNCTION_HPP
8
9#pragma once
10
11#include <concepts>
12#include <tuple>
13
16
17namespace sl::functional
18{
20 {
21 template <class... PackedFns, class... Args>
22 requires (... && std::predicate<PackedFns, Args...>)
23 [[nodiscard]]
24 constexpr bool operator ()(
25 std::tuple<PackedFns...>&& fnPack,
26 Args&&... args
27 ) const
28 noexcept((... && std::is_nothrow_invocable_v<PackedFns, Args...>))
29 {
30 return std::apply(
31 [&]<class... Fns>(Fns&&... fns)
32 {
33 return (std::invoke(std::forward<Fns>(fns), args...) || ...);
34 },
35 std::move(fnPack));
36 }
37 };
38
39 template <concepts::unqualified Derived>
41 {
42 protected:
43 [[nodiscard]]
44 constexpr DisjunctionOperator() noexcept
45 {
46 static_assert(std::is_base_of_v<DisjunctionOperator, Derived>, "Derived doesn't inherit from DisjunctionOperator.");
47 static_assert(
48 std::copy_constructible<Derived> || std::move_constructible<Derived>,
49 "Derived is neither move- nor copy-constructible.");
50 }
51
52 [[nodiscard]]
55
56 [[nodiscard]]
59
61
62 public:
63 template <class Other>
65 [[nodiscard]]
66 friend constexpr auto operator ||(
67 const Derived& first,
68 Other&& other
69 ) noexcept(noexcept(make_composition<DisjunctionStrategy>(first, std::declval<Other>())))
70 {
71 return envelop<closure_template<Derived>::template type>(
72 make_composition<DisjunctionStrategy>(first, std::forward<Other>(other)));
73 }
74
75 template <class Other>
77 [[nodiscard]]
78 friend constexpr auto operator ||(
79 Derived&& first,
80 Other&& other
81 ) noexcept(noexcept(make_composition<DisjunctionStrategy>(std::move(first), std::declval<Other>())))
82 {
83 return envelop<closure_template<Derived>::template type>(
84 make_composition<DisjunctionStrategy>(std::move(first), std::forward<Other>(other)));
85 }
86 };
87}
88
89#endif
Definition: Disjunction.hpp:41
DisjunctionOperator(const DisjunctionOperator &)=default
constexpr DisjunctionOperator() noexcept
Definition: Disjunction.hpp:44
DisjunctionOperator & operator=(const DisjunctionOperator &)=default
DisjunctionOperator(DisjunctionOperator &&)=default
friend constexpr auto operator||(const Derived &first, Other &&other) noexcept(noexcept(make_composition< DisjunctionStrategy >(first, std::declval< Other >())))
Definition: Disjunction.hpp:66
Determines whether the given type satisfies the constraints of a function type.
Definition: BasicClosure.hpp:79
Definition: Arithmetic.hpp:13
Definition: Disjunction.hpp:20