Quantum++  v1.0
A modern C++11 quantum computing library
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 - 2018 Vlad Gheorghiu (vgheorgh@gmail.com)
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<
87  T, to_void<decltype(std::declval<T>().begin()),
88  decltype(std::declval<T>().end()), typename T::value_type>>
89  : std::true_type {};
90 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
91 #pragma GCC diagnostic pop
92 #endif
93 
102 // thanks to @davidhigh http://stackoverflow.com/a/40293333/3093378
103 // silence g++4.8.x warning about non-virtual destructor in inherited class
104 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
105 #pragma GCC diagnostic push
106 #pragma GCC diagnostic ignored "-Weffc++"
107 #endif
108 template <typename Derived>
110  : std::is_base_of<Eigen::MatrixBase<typename std::decay<Derived>::type>,
111  typename std::decay<Derived>::type> {};
112 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
113 #pragma GCC diagnostic pop
114 #endif
115 
122 // silence g++4.8.x warning about non-virtual destructor in inherited class
123 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
124 #pragma GCC diagnostic push
125 #pragma GCC diagnostic ignored "-Weffc++"
126 #endif
127 template <typename T>
128 struct is_complex : std::false_type {};
129 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
130 #pragma GCC diagnostic pop
131 #endif
132 
137 // silence g++4.8.x warning about non-virtual destructor in inherited class
138 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
139 #pragma GCC diagnostic push
140 #pragma GCC diagnostic ignored "-Weffc++"
141 #endif
142 template <typename T>
143 struct is_complex<std::complex<T>> : std::true_type {};
144 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && !__clang__)
145 #pragma GCC diagnostic pop
146 #endif
147 
148 } /* namespace qpp */
149 
150 #endif /* TRAITS_H_ */
Quantum++ main namespace.
Definition: codes.h:35
STL namespace.
typename make_void< Ts... >::type to_void
Alias template that implements the proposal for void_t.
Definition: traits.h:55
void type
Definition: traits.h:46
Checks whether T is compatible with an STL-like iterable container.
Definition: traits.h:71
Checks whether the type is an Eigen matrix expression.
Definition: traits.h:109
Helper for qpp::to_void<> alias template.
Definition: traits.h:45
Checks whether the type is a complex type.
Definition: traits.h:128