tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
negate.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_FUNCTIONAL_NEGATE_HPP
5#define TETL_FUNCTIONAL_NEGATE_HPP
6
7#include <etl/_utility/forward.hpp>
8
9namespace etl {
10
11/// \brief Function object for performing negation. Effectively calls operator-
12/// on an instance of type T.
13/// https://en.cppreference.com/w/cpp/utility/functional/negate
14template <typename T = void>
15struct negate {
16 [[nodiscard]] constexpr auto operator()(T const& arg) const -> T
17 {
18 return static_cast<T>(-arg);
19 }
20};
21
22template <>
23struct negate<void> {
24 using is_transparent = void;
25
26 template <typename T>
27 [[nodiscard]] constexpr auto operator()(T&& arg) const noexcept(noexcept(-etl::forward<T>(arg)))
28 -> decltype(-etl::forward<T>(arg))
29 {
30 return -etl::forward<T>(arg);
31 }
32};
33
34} // namespace etl
35
36#endif // TETL_FUNCTIONAL_NEGATE_HPP
Definition adjacent_find.hpp:9
constexpr auto operator()(T &&arg) const noexcept(noexcept(-etl::forward< T >(arg))) -> decltype(-etl::forward< T >(arg))
Definition negate.hpp:27
Function object for performing negation. Effectively calls operator- on an instance of type T....
Definition negate.hpp:15
constexpr auto operator()(T const &arg) const -> T
Definition negate.hpp:16