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
15namespace internal {
16
17// default functor traits for STL functors:
18
19template<typename T>
20struct functor_traits<std::multiplies<T> >
21{ enum { Cost = NumTraits<T>::MulCost, PacketAccess = false }; };
22
23template<typename T>
24struct functor_traits<std::divides<T> >
25{ enum { Cost = NumTraits<T>::MulCost, PacketAccess = false }; };
26
27template<typename T>
28struct functor_traits<std::plus<T> >
29{ enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; };
30
31template<typename T>
32struct functor_traits<std::minus<T> >
33{ enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; };
34
35template<typename T>
36struct functor_traits<std::negate<T> >
37{ enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; };
38
39template<typename T>
40struct functor_traits<std::logical_or<T> >
41{ enum { Cost = 1, PacketAccess = false }; };
42
43template<typename T>
44struct functor_traits<std::logical_and<T> >
45{ enum { Cost = 1, PacketAccess = false }; };
46
47template<typename T>
48struct functor_traits<std::logical_not<T> >
49{ enum { Cost = 1, PacketAccess = false }; };
50
51template<typename T>
52struct functor_traits<std::greater<T> >
53{ enum { Cost = 1, PacketAccess = false }; };
54
55template<typename T>
56struct functor_traits<std::less<T> >
57{ enum { Cost = 1, PacketAccess = false }; };
58
59template<typename T>
60struct functor_traits<std::greater_equal<T> >
61{ enum { Cost = 1, PacketAccess = false }; };
62
63template<typename T>
64struct functor_traits<std::less_equal<T> >
65{ enum { Cost = 1, PacketAccess = false }; };
66
67template<typename T>
68struct functor_traits<std::equal_to<T> >
69{ enum { Cost = 1, PacketAccess = false }; };
70
71template<typename T>
72struct 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
77template<typename T>
78struct functor_traits<std::binder2nd<T> >
79{ enum { Cost = functor_traits<T>::Cost, PacketAccess = false }; };
80
81template<typename T>
82struct 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
88template<typename T>
89struct 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
93template<typename T>
94struct 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
100template<typename T0,typename T1>
101struct functor_traits<std::project1st<T0,T1> >
102{ enum { Cost = 0, PacketAccess = false }; };
103
104template<typename T0,typename T1>
105struct functor_traits<std::project2nd<T0,T1> >
106{ enum { Cost = 0, PacketAccess = false }; };
107
108template<typename T0,typename T1>
109struct functor_traits<std::select2nd<std::pair<T0,T1> > >
110{ enum { Cost = 0, PacketAccess = false }; };
111
112template<typename T0,typename T1>
113struct functor_traits<std::select1st<std::pair<T0,T1> > >
114{ enum { Cost = 0, PacketAccess = false }; };
115
116template<typename T0,typename T1>
117struct functor_traits<std::unary_compose<T0,T1> >
118{ enum { Cost = functor_traits<T0>::Cost + functor_traits<T1>::Cost, PacketAccess = false }; };
119
120template<typename T0,typename T1,typename T2>
121struct 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