WPILibC++ 2023.4.3-108-ge5452e3
StlFunctors.h
Go to the documentation of this file.
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10#ifndef EIGEN_STL_FUNCTORS_H
11#define EIGEN_STL_FUNCTORS_H
12
13namespace Eigen {
14
15// Portable replacements for certain functors.
16namespace numext {
17
18template<typename T = void>
19struct equal_to {
20 typedef bool result_type;
21 EIGEN_DEVICE_FUNC bool operator()(const T& lhs, const T& rhs) const {
22 return lhs == rhs;
23 }
24};
25
26template<typename T = void>
28 typedef bool result_type;
29 EIGEN_DEVICE_FUNC bool operator()(const T& lhs, const T& rhs) const {
30 return lhs != rhs;
31 }
32};
33
34}
35
36
37namespace internal {
38
39// default functor traits for STL functors:
40
41template<typename T>
42struct functor_traits<std::multiplies<T> >
43{ enum { Cost = NumTraits<T>::MulCost, PacketAccess = false }; };
44
45template<typename T>
46struct functor_traits<std::divides<T> >
47{ enum { Cost = NumTraits<T>::MulCost, PacketAccess = false }; };
48
49template<typename T>
50struct functor_traits<std::plus<T> >
51{ enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; };
52
53template<typename T>
54struct functor_traits<std::minus<T> >
55{ enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; };
56
57template<typename T>
58struct functor_traits<std::negate<T> >
59{ enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; };
60
61template<typename T>
62struct functor_traits<std::logical_or<T> >
63{ enum { Cost = 1, PacketAccess = false }; };
64
65template<typename T>
66struct functor_traits<std::logical_and<T> >
67{ enum { Cost = 1, PacketAccess = false }; };
68
69template<typename T>
70struct functor_traits<std::logical_not<T> >
71{ enum { Cost = 1, PacketAccess = false }; };
72
73template<typename T>
74struct functor_traits<std::greater<T> >
75{ enum { Cost = 1, PacketAccess = false }; };
76
77template<typename T>
78struct functor_traits<std::less<T> >
79{ enum { Cost = 1, PacketAccess = false }; };
80
81template<typename T>
82struct functor_traits<std::greater_equal<T> >
83{ enum { Cost = 1, PacketAccess = false }; };
84
85template<typename T>
86struct functor_traits<std::less_equal<T> >
87{ enum { Cost = 1, PacketAccess = false }; };
88
89template<typename T>
90struct functor_traits<std::equal_to<T> >
91{ enum { Cost = 1, PacketAccess = false }; };
92
93template<typename T>
94struct functor_traits<numext::equal_to<T> >
95 : functor_traits<std::equal_to<T> > {};
96
97template<typename T>
98struct functor_traits<std::not_equal_to<T> >
99{ enum { Cost = 1, PacketAccess = false }; };
100
101template<typename T>
102struct functor_traits<numext::not_equal_to<T> >
103 : functor_traits<std::not_equal_to<T> > {};
104
105#if (EIGEN_COMP_CXXVER < 11)
106// std::binder* are deprecated since c++11 and will be removed in c++17
107template<typename T>
108struct functor_traits<std::binder2nd<T> >
110
111template<typename T>
112struct functor_traits<std::binder1st<T> >
114#endif
115
116#if (EIGEN_COMP_CXXVER < 17)
117// std::unary_negate is deprecated since c++17 and will be removed in c++20
118template<typename T>
119struct functor_traits<std::unary_negate<T> >
120{ enum { Cost = 1 + functor_traits<T>::Cost, PacketAccess = false }; };
121
122// std::binary_negate is deprecated since c++17 and will be removed in c++20
123template<typename T>
124struct functor_traits<std::binary_negate<T> >
125{ enum { Cost = 1 + functor_traits<T>::Cost, PacketAccess = false }; };
126#endif
127
128#ifdef EIGEN_STDEXT_SUPPORT
129
130template<typename T0,typename T1>
131struct functor_traits<std::project1st<T0,T1> >
132{ enum { Cost = 0, PacketAccess = false }; };
133
134template<typename T0,typename T1>
135struct functor_traits<std::project2nd<T0,T1> >
136{ enum { Cost = 0, PacketAccess = false }; };
137
138template<typename T0,typename T1>
139struct functor_traits<std::select2nd<std::pair<T0,T1> > >
140{ enum { Cost = 0, PacketAccess = false }; };
141
142template<typename T0,typename T1>
143struct functor_traits<std::select1st<std::pair<T0,T1> > >
144{ enum { Cost = 0, PacketAccess = false }; };
145
146template<typename T0,typename T1>
147struct functor_traits<std::unary_compose<T0,T1> >
149
150template<typename T0,typename T1,typename T2>
151struct functor_traits<std::binary_compose<T0,T1,T2> >
153
154#endif // EIGEN_STDEXT_SUPPORT
155
156// allow to add new functors and specializations of functor_traits from outside Eigen.
157// this macro is really needed because functor_traits must be specialized after it is declared but before it is used...
158#ifdef EIGEN_FUNCTORS_PLUGIN
159#include EIGEN_FUNCTORS_PLUGIN
160#endif
161
162} // end namespace internal
163
164} // end namespace Eigen
165
166#endif // EIGEN_STL_FUNCTORS_H
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:986
Namespace containing all symbols from the Eigen library.
Definition: Core:141
Definition: Eigen_Colamd.h:50
Definition: BFloat16.h:88
Holds information about the various numeric (i.e.
Definition: NumTraits.h:233
Definition: XprHelper.h:176
@ PacketAccess
Definition: XprHelper.h:180
@ Cost
Definition: XprHelper.h:179
Definition: StlFunctors.h:19
bool result_type
Definition: StlFunctors.h:20
EIGEN_DEVICE_FUNC bool operator()(const T &lhs, const T &rhs) const
Definition: StlFunctors.h:21
Definition: StlFunctors.h:27
EIGEN_DEVICE_FUNC bool operator()(const T &lhs, const T &rhs) const
Definition: StlFunctors.h:29
bool result_type
Definition: StlFunctors.h:28