30 #ifndef SACADO_TRAITS_HPP
31 #define SACADO_TRAITS_HPP
34 #include <type_traits>
41 #ifdef HAVE_SACADO_COMPLEX
59 static const bool value =
false;
65 static const bool value =
false;
75 template <
typename T,
unsigned,
unsigned>
struct ViewFadType {};
79 static const bool value =
false;
87 template <
typename A,
typename B,
typename Enabled =
void>
struct Promote {};
92 typename mpl::enable_if_c< !OverrideDefaultPromote<A>::value >
::type > {
97 template <
typename A,
typename B>
99 typename mpl::enable_if_c< std::is_convertible<A,B>::value &&
100 !std::is_convertible<B,A>::value &&
101 !OverrideDefaultPromote<A>::value &&
102 !OverrideDefaultPromote<B>::value
108 template <
typename A,
typename B>
110 typename mpl::enable_if_c< std::is_convertible<B,A>::value &&
111 !std::is_convertible<A,B>::value &&
112 !OverrideDefaultPromote<A>::value &&
113 !OverrideDefaultPromote<B>::value
122 template <
typename A,
typename B>
124 typename mpl::enable_if_c< std::is_convertible<A,B>::value &&
125 std::is_convertible<B,A>::value &&
126 !std::is_same<A,B>::value &&
127 ( IsExpr<A>::value ||
128 IsExpr<B>::value ) >
::type >
140 template <
typename A,
typename B>
142 typename mpl::enable_if_c< !std::is_convertible<A,B>::value &&
143 !std::is_convertible<B,A>::value &&
145 std::is_convertible< B, typename BaseExprType< typename A::value_type >::type >::value
156 template <
typename A,
typename B>
158 typename mpl::enable_if_c< !std::is_convertible<A,B>::value &&
159 !std::is_convertible<B,A>::value &&
161 std::is_convertible< A, typename BaseExprType< typename B::value_type >::type >::value
172 template <
typename A,
typename B>
174 typename mpl::enable_if_c< !std::is_convertible<A,B>::value &&
175 !std::is_convertible<B,A>::value &&
178 std::is_same< typename BaseExprType< typename A::value_type >::type,
179 typename BaseExprType< typename B::value_type >::type >::value
188 #define SACADO_PROMOTE_SPECIALIZATION(type1,type2,type3) \
189 template <> struct Promote< type1, type2, void > { \
190 typedef type3 type; \
192 template <> struct Promote< type2, type1, void > { \
193 typedef type3 type; \
201 #ifdef HAVE_SACADO_COMPLEX
210 #endif // HAVE_SACADO_COMPLEX
212 #undef SACADO_PROMOTE_SPECIALIZATION
216 #define SACADO_AD_PROMOTE_SPEC(NS, AD)
218 #define SACADO_AD_PROMOTE_SPEC2(NS, AD)
220 #define SACADO_FAD_PROMOTE_SPEC(NS, FAD)
222 #define SACADO_SFAD_PROMOTE_SPEC(NS, FAD)
224 #define SACADO_EXPR_PROMOTE_SPEC(NS)
226 #define SACADO_VFAD_PROMOTE_SPEC(NS)
228 #define SACADO_RAD_PROMOTE_SPEC(NS) \
230 template <typename> class ADvar; \
231 template <typename> class ADvari; \
233 template <typename T> \
234 struct OverrideDefaultPromote< NS :: ADvari <T>& > { \
235 static const bool value = true; \
237 template <typename T> \
238 struct Promote< NS :: ADvar <T>, \
239 NS :: ADvari <T>& > { \
240 typedef NS :: ADvar <T> type; \
242 template <typename T> \
243 struct Promote< NS :: ADvari <T>&, \
244 NS :: ADvar <T> > { \
245 typedef NS :: ADvar <T> type; \
247 template <typename T> \
248 struct Promote< NS :: ADvari <T>&, \
249 typename NS :: ADvari <T>::value_type > { \
250 typedef NS :: ADvar <T> type; \
252 template <typename T> \
253 struct Promote< typename NS :: ADvari <T>::value_type, \
254 NS :: ADvari <T>& > { \
255 typedef NS :: ADvar <T> type; \
257 template <typename T> \
258 struct Promote< NS :: ADvari <T>&, \
259 typename dummy< typename NS :: ADvari <T>::value_type, \
260 typename NS :: ADvari <T>::scalar_type \
262 typedef NS :: ADvar <T> type; \
264 template <typename T> \
265 struct Promote< typename dummy< typename NS :: ADvari <T>::value_type, \
266 typename NS :: ADvari <T>::scalar_type \
268 NS :: ADvari <T>& > { \
269 typedef NS :: ADvar <T> type; \
344 template <
typename T>
struct Value {
350 template <
typename T>
struct Value<const
T> {
378 template <
typename T>
392 static std::string
eval() {
return ""; }
398 static bool eval(
const T&
x,
const T&
y) {
return x ==
y; }
420 template <
typename T>
struct IsFad {
425 template <
typename T>
struct IsFad< const
T >
431 template <
typename T>
437 template <
typename T>
443 #define SACADO_BUILTIN_SPECIALIZATION(t,NAME) \
444 template <> struct ScalarType< t > { \
447 template <> struct ValueType< t > { \
450 template <> struct IsADType< t > { \
451 static const bool value = false; \
453 template <> struct IsScalarType< t > { \
454 static const bool value = true; \
456 template <> struct Value< t > { \
457 SACADO_INLINE_FUNCTION \
458 static const t& eval(const t& x) { return x; } \
460 template <> struct ScalarValue< t > { \
461 SACADO_INLINE_FUNCTION \
462 static const t& eval(const t& x) { return x; } \
464 template <> struct StringName< t > { \
465 static std::string eval() { return NAME; } \
467 template <> struct IsEqual< t > { \
468 SACADO_INLINE_FUNCTION \
469 static bool eval(const t& x, const t& y) { \
472 template <> struct IsStaticallySized< t > { \
473 static const bool value = true; \
476 #define SACADO_BUILTIN_SPECIALIZATION_COMPLEX(t,NAME) \
477 template <> struct ScalarType< t > { \
480 template <> struct ValueType< t > { \
483 template <> struct IsADType< t > { \
484 static const bool value = false; \
486 template <> struct IsScalarType< t > { \
487 static const bool value = true; \
489 template <> struct Value< t > { \
490 static const t& eval(const t& x) { return x; } \
492 template <> struct ScalarValue< t > { \
493 static const t& eval(const t& x) { return x; } \
495 template <> struct StringName< t > { \
496 static std::string eval() { return NAME; } \
498 template <> struct IsEqual< t > { \
499 static bool eval(const t& x, const t& y) { \
502 template <> struct IsStaticallySized< t > { \
503 static const bool value = true; \
514 #ifdef HAVE_SACADO_COMPLEX
519 #undef SACADO_BUILTIN_SPECIALIZATION
520 #undef SACADO_BUILTIN_SPECIALIZATION_COMPLEX
522 template<
typename T , T v ,
bool NonZero = ( v != T(0) ) >
537 template<
typename T , T zero >
552 #endif // SACADO_TRAITS_HPP
static SACADO_INLINE_FUNCTION const T & eval(const T &x)
SACADO_INLINE_FUNCTION ScalarType< T >::type scalarValue(const T &x)
A simple template function for invoking ScalarValue<>
static SACADO_INLINE_FUNCTION const value_type & eval(const T &x)
Base template specification for marking constants.
static std::string eval()
#define SACADO_PROMOTE_SPECIALIZATION(type1, type2, type3)
Specialization of Promote to builtin types.
SACADO_INLINE_FUNCTION integral_nonzero()
SACADO_INLINE_FUNCTION integral_nonzero & operator=(const integral_nonzero &v)
static SACADO_INLINE_FUNCTION void eval(T &x)
Base template specification for ScalarValue.
Base template specification for ScalarType.
Base template specification for whether a type is a Fad type.
Base template specification for string names of types.
static SACADO_INLINE_FUNCTION const T & eval(const T &x)
Base template specification for IsADType.
Base template specification for static size.
Base template specification for Value.
Base template specification for IsSimdType.
const ScalarType< T >::type type
SACADO_INLINE_FUNCTION integral_nonzero()
ValueType< T >::type value_type
Determine whether a given type is a view.
Base template specification for testing equivalence.
Get the base Fad type from a view/expression.
SACADO_INLINE_FUNCTION integral_nonzero & operator=(const T &)
#define SACADO_BUILTIN_SPECIALIZATION_COMPLEX(t, NAME)
Remove const from a type.
Do not initialize the derivative array.
const ValueType< T >::type type
integral_nonzero< T, v > type
static SACADO_INLINE_FUNCTION bool eval(const T &x, const T &y)
SACADO_INLINE_FUNCTION integral_nonzero(const integral_nonzero &v)
#define SACADO_BUILTIN_SPECIALIZATION(t, NAME)
Specialization of above classes to builtin types.
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors...
integral_nonzero< T, 0 > type
ScalarType< T >::type scalar_type
Initialize the derivative array.
Base template specification for IsScalarType.
static SACADO_INLINE_FUNCTION const scalar_type & eval(const T &x)
#define SACADO_INLINE_FUNCTION
static const unsigned value
SACADO_INLINE_FUNCTION integral_nonzero & operator=(const integral_nonzero &)
SACADO_INLINE_FUNCTION integral_nonzero(const integral_nonzero &)
SACADO_INLINE_FUNCTION integral_nonzero(const T &)
SACADO_INLINE_FUNCTION integral_nonzero(const T &v)
Base template specification for ValueType.
Base template specification for testing whether type is statically sized.
SACADO_INLINE_FUNCTION integral_nonzero & operator=(const T &v)
Get view type for any Fad type.