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