Quantum++  v1.0-rc2
A modern C++11 quantum computing library
traits.h
Go to the documentation of this file.
1 /*
2  * Quantum++
3  *
4  * Copyright (c) 2013 - 2017 Vlad Gheorghiu (vgheorgh@gmail.com)
5  *
6  * This file is part of Quantum++.
7  *
8  * Quantum++ is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * Quantum++ is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with Quantum++. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
27 #ifndef TRAITS_H_
28 #define TRAITS_H_
29 
30 namespace qpp
31 {
32 // Citing from http://en.cppreference.com/w/cpp/types/void_t:
33 // "Until CWG 1558 (a C++14 defect), unused parameters in alias templates were
34 // not guaranteed to ensure SFINAE and could be ignored, so earlier compilers
35 // require a more complex definition of void_t, such as:"
40 template<typename... Ts> struct make_void { typedef void type;};
41 
47 template<typename... Ts> using to_void = typename make_void<Ts...>::type;
48 
57 // silence g++4.8.x warning about non-virtual destructor in inherited class
58 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
59 #pragma GCC diagnostic push
60 #pragma GCC diagnostic ignored "-Weffc++"
61 #endif
62 template<typename T, typename = void>
63 struct is_iterable : std::false_type
64 {
65 };
66 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
67 #pragma GCC diagnostic pop
68 #endif
69 
74 // silence g++4.8.x warning about non-virtual destructor in inherited class
75 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
76 #pragma GCC diagnostic push
77 #pragma GCC diagnostic ignored "-Weffc++"
78 #endif
79 template<typename T>
80 struct is_iterable<T,
81  to_void<decltype(std::declval<T>().begin()),
82  decltype(std::declval<T>().end()),
83  typename T::value_type
84  >> : std::true_type
85 {
86 };
87 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
88 #pragma GCC diagnostic pop
89 #endif
90 
99 // thanks to @davidhigh http://stackoverflow.com/a/40293333/3093378
100 // silence g++4.8.x warning about non-virtual destructor in inherited class
101 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
102 #pragma GCC diagnostic push
103 #pragma GCC diagnostic ignored "-Weffc++"
104 #endif
105 template<typename Derived>
106 struct is_matrix_expression : std::is_base_of
107  <
108  Eigen::MatrixBase<typename std::decay<Derived>::type>,
109  typename std::decay<Derived>::type
110  >
111 {
112 };
113 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
114 #pragma GCC diagnostic pop
115 #endif
116 
123 // silence g++4.8.x warning about non-virtual destructor in inherited class
124 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
125 #pragma GCC diagnostic push
126 #pragma GCC diagnostic ignored "-Weffc++"
127 #endif
128 template<typename T>
129 struct is_complex : std::false_type
130 {
131 };
132 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
133 #pragma GCC diagnostic pop
134 #endif
135 
140 // silence g++4.8.x warning about non-virtual destructor in inherited class
141 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
142 #pragma GCC diagnostic push
143 #pragma GCC diagnostic ignored "-Weffc++"
144 #endif
145 template<typename T>
146 struct is_complex<std::complex<T>> : std::true_type
147 {
148 };
149 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
150 #pragma GCC diagnostic pop
151 #endif
152 
153 
154 } /* namespace qpp */
155 
156 #endif /* TRAITS_H_ */
157 
Quantum++ main namespace.
Definition: codes.h:30
STL namespace.
typename make_void< Ts... >::type to_void
Alias template that implements the proposal for void_t.
Definition: traits.h:47
void type
Definition: traits.h:40
Checks whether T is compatible with an STL-like iterable container.
Definition: traits.h:63
Checks whether the type is an Eigen matrix expression.
Definition: traits.h:106
Helper for qpp::to_void<> alias template.
Definition: traits.h:40
Checks whether the type is a complex type.
Definition: traits.h:129