Skip to content

Commit

Permalink
Merge pull request #510 from Cytnx-dev/is-complex
Browse files Browse the repository at this point in the history
Add a helper class to check if a type is `complex`
  • Loading branch information
manuschneider authored Nov 14, 2024
2 parents 9f46fd4 + fca444d commit 50c0553
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions include/Type.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#ifndef _H_TYPE_
#define _H_TYPE_
#ifndef INCLUDE_TYPE_H_
#define INCLUDE_TYPE_H_

#include <string>
#include <complex>
#include <cstdint>
#include <string>
#include <type_traits>
#include <vector>
#include <stdint.h>
#include <climits>
#include <typeinfo>
#include <unordered_map>
#include <typeindex>

#include "cytnx_error.hpp"

#define MKL_Complex8 std::complex<float>
Expand Down Expand Up @@ -63,6 +61,23 @@ namespace cytnx {
typedef std::complex<double> cytnx_complex128;
typedef bool cytnx_bool;

namespace internal {
template <class>
struct is_complex_impl : std::false_type {};

template <class T>
struct is_complex_impl<std::complex<T>> : std::true_type {};

} // namespace internal

template <typename T>
using is_complex = internal::is_complex_impl<std::remove_cv_t<T>>;

// is_complex_v checks if a data type is of type std::complex
// usage: is_complex_v<T> returns true or false for a data type T
template <typename T>
constexpr bool is_complex_v = is_complex<T>::value;

/// @cond
struct __type {
enum __pybind_type {
Expand Down Expand Up @@ -219,4 +234,4 @@ namespace cytnx {

} // namespace cytnx

#endif
#endif // INCLUDE_TYPE_H_

0 comments on commit 50c0553

Please sign in to comment.