XACC
traits.h
Go to the documentation of this file.
1 /*
2  * This file is part of Quantum++.
3  *
4  * MIT License
5  *
6  * Copyright (c) 2013 - 2020 Vlad Gheorghiu.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  */
26 
32 #ifndef TRAITS_H_
33 #define TRAITS_H_
34 
35 namespace qpp {
36 // Citing from http://en.cppreference.com/w/cpp/types/void_t:
37 // "Until CWG 1558 (a C++14 defect), unused parameters in alias templates were
38 // not guaranteed to ensure SFINAE and could be ignored, so earlier compilers
39 // require a more complex definition of void_t, such as:"
44 template <typename... Ts>
45 struct make_void {
46  typedef void type;
47 };
48 
54 template <typename... Ts>
55 using to_void = typename make_void<Ts...>::type;
56 
65 // silence g++4.8.x warning about non-virtual destructor in inherited class
66 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
67 #pragma GCC diagnostic push
68 #pragma GCC diagnostic ignored "-Weffc++"
69 #endif
70 template <typename T, typename = void>
71 struct is_iterable : std::false_type {};
72 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
73 #pragma GCC diagnostic pop
74 #endif
75 
80 // silence g++4.8.x warning about non-virtual destructor in inherited class
81 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
82 #pragma GCC diagnostic push
83 #pragma GCC diagnostic ignored "-Weffc++"
84 #endif
85 template <typename T>
86 struct is_iterable<T, to_void<decltype(std::declval<T>().begin()),
87  decltype(std::declval<T>().end()),
88  decltype(*(std::declval<T>().begin()))>>
89  : std::true_type {};
90 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
91 #pragma GCC diagnostic pop
92 #endif
93 
101 // thanks to @davidhigh http://stackoverflow.com/a/40293333/3093378
102 // silence g++4.8.x warning about non-virtual destructor in inherited class
103 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
104 #pragma GCC diagnostic push
105 #pragma GCC diagnostic ignored "-Weffc++"
106 #endif
107 template <typename Derived>
108 struct is_matrix_expression
109  : std::is_base_of<Eigen::MatrixBase<typename std::decay<Derived>::type>,
110  typename std::decay<Derived>::type> {};
111 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
112 #pragma GCC diagnostic pop
113 #endif
114 
121 // silence g++4.8.x warning about non-virtual destructor in inherited class
122 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
123 #pragma GCC diagnostic push
124 #pragma GCC diagnostic ignored "-Weffc++"
125 #endif
126 template <typename T>
127 struct is_complex : std::false_type {};
128 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
129 #pragma GCC diagnostic pop
130 #endif
131 
136 // silence g++4.8.x warning about non-virtual destructor in inherited class
137 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
138 #pragma GCC diagnostic push
139 #pragma GCC diagnostic ignored "-Weffc++"
140 #endif
141 template <typename T>
142 struct is_complex<std::complex<T>> : std::true_type {};
143 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
144 #pragma GCC diagnostic pop
145 #endif
146 
147 } /* namespace qpp */
148 
149 #endif /* TRAITS_H_ */
Quantum++ main namespace.
Definition: circuits.h:35