Warning: This file is not a C or C++ file. It does not have highlighting.

1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___CXX03___FUNCTIONAL_OPERATIONS_H
11#define _LIBCPP___CXX03___FUNCTIONAL_OPERATIONS_H
12
13#include <__cxx03/__config>
14#include <__cxx03/__functional/binary_function.h>
15#include <__cxx03/__functional/unary_function.h>
16#include <__cxx03/__type_traits/desugars_to.h>
17#include <__cxx03/__utility/forward.h>
18
19#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20# pragma GCC system_header
21#endif
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25// Arithmetic operations
26
27template <class _Tp>
28struct _LIBCPP_TEMPLATE_VIS plus : __binary_function<_Tp, _Tp, _Tp> {
29 typedef _Tp __result_type; // used by valarray
30 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; }
31};
32_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(plus);
33
34// The non-transparent std::plus specialization is only equivalent to a raw plus
35// operator when we don't perform an implicit conversion when calling it.
36template <class _Tp>
37inline const bool __desugars_to_v<__plus_tag, plus<_Tp>, _Tp, _Tp> = true;
38
39template <class _Tp, class _Up>
40inline const bool __desugars_to_v<__plus_tag, plus<void>, _Tp, _Up> = true;
41
42template <class _Tp>
43struct _LIBCPP_TEMPLATE_VIS minus : __binary_function<_Tp, _Tp, _Tp> {
44 typedef _Tp __result_type; // used by valarray
45 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x - __y; }
46};
47_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(minus);
48
49template <class _Tp>
50struct _LIBCPP_TEMPLATE_VIS multiplies : __binary_function<_Tp, _Tp, _Tp> {
51 typedef _Tp __result_type; // used by valarray
52 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x * __y; }
53};
54_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(multiplies);
55
56template <class _Tp>
57struct _LIBCPP_TEMPLATE_VIS divides : __binary_function<_Tp, _Tp, _Tp> {
58 typedef _Tp __result_type; // used by valarray
59 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x / __y; }
60};
61_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(divides);
62
63template <class _Tp>
64struct _LIBCPP_TEMPLATE_VIS modulus : __binary_function<_Tp, _Tp, _Tp> {
65 typedef _Tp __result_type; // used by valarray
66 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x % __y; }
67};
68_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(modulus);
69
70template <class _Tp = void>
71struct _LIBCPP_TEMPLATE_VIS negate : __unary_function<_Tp, _Tp> {
72 typedef _Tp __result_type; // used by valarray
73 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return -__x; }
74};
75_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(negate);
76
77// Bitwise operations
78
79template <class _Tp>
80struct _LIBCPP_TEMPLATE_VIS bit_and : __binary_function<_Tp, _Tp, _Tp> {
81 typedef _Tp __result_type; // used by valarray
82 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x & __y; }
83};
84_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_and);
85
86template <class _Tp>
87struct _LIBCPP_TEMPLATE_VIS bit_or : __binary_function<_Tp, _Tp, _Tp> {
88 typedef _Tp __result_type; // used by valarray
89 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x | __y; }
90};
91_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_or);
92
93template <class _Tp = void>
94struct _LIBCPP_TEMPLATE_VIS bit_xor : __binary_function<_Tp, _Tp, _Tp> {
95 typedef _Tp __result_type; // used by valarray
96 _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x ^ __y; }
97};
98_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(bit_xor);
99
100// Comparison operations
101
102template <class _Tp>
103struct _LIBCPP_TEMPLATE_VIS equal_to : __binary_function<_Tp, _Tp, bool> {
104 typedef bool __result_type; // used by valarray
105 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x == __y; }
106};
107_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(equal_to);
108
109// The non-transparent std::equal_to specialization is only equivalent to a raw equality
110// comparison when we don't perform an implicit conversion when calling it.
111template <class _Tp>
112inline const bool __desugars_to_v<__equal_tag, equal_to<_Tp>, _Tp, _Tp> = true;
113
114// In the transparent case, we do not enforce that
115template <class _Tp, class _Up>
116inline const bool __desugars_to_v<__equal_tag, equal_to<void>, _Tp, _Up> = true;
117
118template <class _Tp>
119struct _LIBCPP_TEMPLATE_VIS not_equal_to : __binary_function<_Tp, _Tp, bool> {
120 typedef bool __result_type; // used by valarray
121 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x != __y; }
122};
123_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(not_equal_to);
124
125template <class _Tp>
126struct _LIBCPP_TEMPLATE_VIS less : __binary_function<_Tp, _Tp, bool> {
127 typedef bool __result_type; // used by valarray
128 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; }
129};
130_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(less);
131
132template <class _Tp>
133inline const bool __desugars_to_v<__less_tag, less<_Tp>, _Tp, _Tp> = true;
134
135template <class _Tp>
136struct _LIBCPP_TEMPLATE_VIS less_equal : __binary_function<_Tp, _Tp, bool> {
137 typedef bool __result_type; // used by valarray
138 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x <= __y; }
139};
140_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(less_equal);
141
142template <class _Tp>
143struct _LIBCPP_TEMPLATE_VIS greater_equal : __binary_function<_Tp, _Tp, bool> {
144 typedef bool __result_type; // used by valarray
145 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x >= __y; }
146};
147_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(greater_equal);
148
149template <class _Tp>
150struct _LIBCPP_TEMPLATE_VIS greater : __binary_function<_Tp, _Tp, bool> {
151 typedef bool __result_type; // used by valarray
152 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x > __y; }
153};
154_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(greater);
155
156// Logical operations
157
158template <class _Tp>
159struct _LIBCPP_TEMPLATE_VIS logical_and : __binary_function<_Tp, _Tp, bool> {
160 typedef bool __result_type; // used by valarray
161 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x && __y; }
162};
163_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_and);
164
165template <class _Tp>
166struct _LIBCPP_TEMPLATE_VIS logical_not : __unary_function<_Tp, bool> {
167 typedef bool __result_type; // used by valarray
168 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x) const { return !__x; }
169};
170_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_not);
171
172template <class _Tp>
173struct _LIBCPP_TEMPLATE_VIS logical_or : __binary_function<_Tp, _Tp, bool> {
174 typedef bool __result_type; // used by valarray
175 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Tp& __y) const { return __x || __y; }
176};
177_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(logical_or);
178
179_LIBCPP_END_NAMESPACE_STD
180
181#endif // _LIBCPP___CXX03___FUNCTIONAL_OPERATIONS_H
182

Warning: This file is not a C or C++ file. It does not have highlighting.

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of libcxx/include/__cxx03/__functional/operations.h