Simple-Utility v2.3.1
Loading...
Searching...
No Matches
Conjunction.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_CONJUNCTION_HPP
7#define SIMPLE_UTILITY_FUNCTIONAL_MIXINS_CONJUNCTION_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 ConjunctionOperator() noexcept
45 {
46 static_assert(std::is_base_of_v<ConjunctionOperator, Derived>, "Derived doesn't inherit from ConjunctionOperator.");
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<ConjunctionStrategy>(first, std::declval<Other>())))
70 {
71 return envelop<closure_template<Derived>::template type>(
72 make_composition<ConjunctionStrategy>(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<ConjunctionStrategy>(std::move(first), std::declval<Other>())))
82 {
83 return envelop<closure_template<Derived>::template type>(
84 make_composition<ConjunctionStrategy>(std::move(first), std::forward<Other>(other)));
85 }
86 };
87}
88
89#endif
Definition: Conjunction.hpp:41
constexpr ConjunctionOperator() noexcept
Definition: Conjunction.hpp:44
ConjunctionOperator(const ConjunctionOperator &)=default
ConjunctionOperator & operator=(const ConjunctionOperator &)=default
friend constexpr auto operator&&(const Derived &first, Other &&other) noexcept(noexcept(make_composition< ConjunctionStrategy >(first, std::declval< Other >())))
Definition: Conjunction.hpp:66
ConjunctionOperator(ConjunctionOperator &&)=default
Determines whether the given type satisfies the constraints of a function type.
Definition: BasicClosure.hpp:79
Definition: Arithmetic.hpp:13
Definition: Conjunction.hpp:20