SOPT
Sparse OPTimisation
real_type.h
Go to the documentation of this file.
1 #ifndef SOPT_REAL_TYPE_H
2 #define SOPT_REAL_TYPE_H
3 
4 #include "sopt/config.h"
5 #include <complex>
6 #include <type_traits>
7 
8 namespace sopt {
9 namespace details {
10 
11 // Checks wether a type has contains a type "value_type"
12 template <typename T, typename Enable = void>
13 struct HasValueType {
14  using Have = char[1];
15  using HaveNot = char[2];
16 
17  struct Fallback {
18  struct value_type {};
19  };
20  struct Derived : T, Fallback {};
21  template <typename U>
22  static Have &test(typename U::value_type *);
23  template <typename U>
24  static HaveNot &test(U *);
25 
26  public:
27  static constexpr bool value = sizeof(test<Derived>(nullptr)) == sizeof(HaveNot);
28 };
29 // Specialization for fundamental type that cannot be derived from
30 template <typename T>
31 struct HasValueType<T, typename std::enable_if<std::is_fundamental<T>::value>::type>
32  : std::false_type {};
34 template <typename T, bool = details::HasValueType<T>::value>
36 template <typename T>
37 class has_value_type<T, true> : public std::true_type {};
38 template <typename T>
39 class has_value_type<T, false> : public std::false_type {};
41 template <typename T, bool = has_value_type<T>::value>
43 template <typename T>
44 class underlying_value_type<T, false> {
45  public:
46  using type = T;
47 };
48 template <typename T>
49 class underlying_value_type<T, true> {
50  public:
52 };
53 } // namespace details
55 template <typename T>
58 template <typename T, typename SP = void>
59 struct is_complex : public std::false_type {};
61 template <typename T>
62 struct is_complex<std::complex<T>, void> : public std::true_type {};
63 } // namespace sopt
64 #endif
Detects whether a class contains a value_type type.
Definition: real_type.h:35
typename underlying_value_type< typename T::value_type >::type type
Definition: real_type.h:51
Computes inner-most element type.
Definition: real_type.h:42
static Have & test(typename U::value_type *)
static constexpr bool value
Definition: real_type.h:27
static HaveNot & test(U *)
True if underlying type is complex.
Definition: real_type.h:59