Simple-Utility v2.3.1
Loading...
Searching...
No Matches
Negation.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_NEGATION_HPP
7#define SIMPLE_UTILITY_FUNCTIONAL_MIXINS_NEGATION_HPP
8
9#pragma once
10
11#include <concepts>
12#include <functional>
13
16
17namespace sl::functional
18{
19 template <concepts::unqualified Derived>
21 {
22 private:
23 [[nodiscard]]
24 constexpr const Derived& derived() const noexcept
25 {
26 return static_cast<const Derived&>(*this);
27 }
28
29 [[nodiscard]]
30 constexpr Derived& derived() noexcept
31 {
32 return static_cast<Derived&>(*this);
33 }
34
35 protected:
36 [[nodiscard]]
37 constexpr NegationOperator() noexcept
38 {
39 static_assert(std::is_base_of_v<NegationOperator, Derived>, "Derived doesn't inherit from NegationOperator.");
40 static_assert(
41 std::copy_constructible<Derived> || std::move_constructible<Derived>,
42 "Derived is neither move- nor copy-constructible.");
43 }
44
45 [[nodiscard]]
48
49 [[nodiscard]]
52
53 ~NegationOperator() = default;
54
55 public:
56 [[nodiscard]]
57 constexpr auto operator !() const & noexcept(std::is_nothrow_copy_constructible_v<Derived>)
58 {
59 return envelop<closure_template<Derived>::template type>(
60 std::not_fn(derived()));
61 }
62
63 [[nodiscard]]
64 constexpr auto operator !() && noexcept(std::is_nothrow_move_constructible_v<Derived>)
65 {
66 return envelop<closure_template<Derived>::template type>(
67 std::not_fn(std::move(derived())));
68 }
69 };
70}
71
72#endif
Definition: Negation.hpp:21
NegationOperator(NegationOperator &&)=default
NegationOperator(const NegationOperator &)=default
NegationOperator & operator=(const NegationOperator &)=default
constexpr NegationOperator() noexcept
Definition: Negation.hpp:37
constexpr auto operator!() const &noexcept(std::is_nothrow_copy_constructible_v< Derived >)
Definition: Negation.hpp:57
Definition: Arithmetic.hpp:13