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 
13 #include "../InternalHeaderCheck.h"
14 
15 namespace Eigen {
16 namespace internal {
17 
18 // default functor traits for STL functors:
19 
20 template<typename T>
21 struct functor_traits<std::multiplies<T> >
22 { enum { Cost = NumTraits<T>::MulCost, PacketAccess = false }; };
23 
24 template<typename T>
25 struct functor_traits<std::divides<T> >
26 { enum { Cost = NumTraits<T>::MulCost, PacketAccess = false }; };
27 
28 template<typename T>
29 struct functor_traits<std::plus<T> >
30 { enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; };
31 
32 template<typename T>
33 struct functor_traits<std::minus<T> >
34 { enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; };
35 
36 template<typename T>
37 struct functor_traits<std::negate<T> >
38 { enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; };
39 
40 template<typename T>
41 struct functor_traits<std::logical_or<T> >
42 { enum { Cost = 1, PacketAccess = false }; };
43 
44 template<typename T>
45 struct functor_traits<std::logical_and<T> >
46 { enum { Cost = 1, PacketAccess = false }; };
47 
48 template<typename T>
49 struct functor_traits<std::logical_not<T> >
50 { enum { Cost = 1, PacketAccess = false }; };
51 
52 template<typename T>
53 struct functor_traits<std::greater<T> >
54 { enum { Cost = 1, PacketAccess = false }; };
55 
56 template<typename T>
57 struct functor_traits<std::less<T> >
58 { enum { Cost = 1, PacketAccess = false }; };
59 
60 template<typename T>
61 struct functor_traits<std::greater_equal<T> >
62 { enum { Cost = 1, PacketAccess = false }; };
63 
64 template<typename T>
65 struct functor_traits<std::less_equal<T> >
66 { enum { Cost = 1, PacketAccess = false }; };
67 
68 template<typename T>
69 struct functor_traits<std::equal_to<T> >
70 { enum { Cost = 1, PacketAccess = false }; };
71 
72 template<typename T>
73 struct functor_traits<std::not_equal_to<T> >
74 { enum { Cost = 1, PacketAccess = false }; };
75 
76 #if (EIGEN_COMP_CXXVER < 17)
77 // std::unary_negate is deprecated since c++17 and will be removed in c++20
78 template<typename T>
79 struct functor_traits<std::unary_negate<T> >
80 { enum { Cost = 1 + functor_traits<T>::Cost, PacketAccess = false }; };
81 
82 // std::binary_negate is deprecated since c++17 and will be removed in c++20
83 template<typename T>
84 struct functor_traits<std::binary_negate<T> >
85 { enum { Cost = 1 + functor_traits<T>::Cost, PacketAccess = false }; };
86 #endif
87 
88 #ifdef EIGEN_STDEXT_SUPPORT
89 
90 template<typename T0,typename T1>
91 struct functor_traits<std::project1st<T0,T1> >
92 { enum { Cost = 0, PacketAccess = false }; };
93 
94 template<typename T0,typename T1>
95 struct functor_traits<std::project2nd<T0,T1> >
96 { enum { Cost = 0, PacketAccess = false }; };
97 
98 template<typename T0,typename T1>
99 struct functor_traits<std::select2nd<std::pair<T0,T1> > >
100 { enum { Cost = 0, PacketAccess = false }; };
101 
102 template<typename T0,typename T1>
103 struct functor_traits<std::select1st<std::pair<T0,T1> > >
104 { enum { Cost = 0, PacketAccess = false }; };
105 
106 template<typename T0,typename T1>
107 struct functor_traits<std::unary_compose<T0,T1> >
108 { enum { Cost = functor_traits<T0>::Cost + functor_traits<T1>::Cost, PacketAccess = false }; };
109 
110 template<typename T0,typename T1,typename T2>
111 struct functor_traits<std::binary_compose<T0,T1,T2> >
112 { enum { Cost = functor_traits<T0>::Cost + functor_traits<T1>::Cost + functor_traits<T2>::Cost, PacketAccess = false }; };
113 
114 #endif // EIGEN_STDEXT_SUPPORT
115 
116 // allow to add new functors and specializations of functor_traits from outside Eigen.
117 // this macro is really needed because functor_traits must be specialized after it is declared but before it is used...
118 #ifdef EIGEN_FUNCTORS_PLUGIN
119 #include EIGEN_FUNCTORS_PLUGIN
120 #endif
121 
122 } // end namespace internal
123 
124 } // end namespace Eigen
125 
126 #endif // EIGEN_STL_FUNCTORS_H
: InteropHeaders
Definition: Core:139
Definition: BFloat16.h:222