Automatic Differentiation
 
Loading...
Searching...
No Matches
plain_type.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_META_PLAIN_TYPE_HPP
2#define STAN_MATH_PRIM_META_PLAIN_TYPE_HPP
3
7#include <type_traits>
8
9namespace stan {
10
16template <typename T, typename Enable = void>
17struct plain_type {
18 using type = std::decay_t<T>;
19};
20
21template <typename T>
23
34template <typename T>
37 using type = std::conditional_t<std::is_same<std::decay_t<T>, T1>::value,
38 const T1&, T1>;
39};
40
41template <typename T>
43
44namespace internal {
45// primary template handles types that have no nested ::type member:
46template <class, class = void>
47struct has_plain_object : std::false_type {};
48
49// specialization recognizes types that do have a nested ::type member:
50template <class T>
51struct has_plain_object<T, void_t<typename std::decay_t<T>::PlainObject>>
52 : std::true_type {};
53
54// primary template handles types that have no nested ::type member:
55template <class, class = void>
56struct has_eval : std::false_type {};
57
58// specialization recognizes types that do have a nested ::type member:
59template <class T>
60struct has_eval<T, void_t<decltype(std::declval<std::decay_t<T>&>().eval())>>
61 : std::true_type {};
62
63} // namespace internal
64
70template <typename T>
71struct plain_type<T, require_t<bool_constant<internal::has_eval<T>::value
72 && is_eigen<T>::value>>> {
73 using type = std::decay_t<decltype(std::declval<T&>().eval())>;
74};
75
76template <typename T>
78 T, require_t<bool_constant<!internal::has_eval<T>::value
80 && is_eigen<T>::value>>> {
81 using type = typename std::decay_t<T>::PlainObject;
82};
83
84} // namespace stan
85
86#endif // STAN_MATH_PRIM_META_PLAIN_TYPE_HPP
std::integral_constant< bool, B > bool_constant
Alias for structs used for wraps a static constant of bool.
typename plain_type< T >::type plain_type_t
typename eval_return_type< T >::type eval_return_type_t
std::enable_if_t< Check::value > require_t
If condition is true, template is enabled.
typename make_void< Ts... >::type void_t
Utility metafunction that maps a sequence of any types to the type void This metafunction is used in ...
Definition void_t.hpp:21
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9
STL namespace.
std::conditional_t< std::is_same< std::decay_t< T >, T1 >::value, const T1 &, T1 > type
plain_type_t< T > T1
Determines return type of calling .eval() on Eigen expression.
Check if type derives from EigenBase
Definition is_eigen.hpp:21
std::decay_t< T > type
Determines plain (non expression) type associated with T.