Skip to content

Commit d6b6aa5

Browse files
authored
Merge pull request #1900 from IntelPython/align-is_complex-with-stl-wrappers
Add support of CV-qualifiers in `is_complex<T>` helper
2 parents 3d5ef0a + 2e39e98 commit d6b6aa5

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3333
* Fix warning in documentation generation caused by `diff` docstring [gh-1855](https://github.com/IntelPython/dpctl/pull/1855)
3434
* Fix additional warnings when generating docs [gh-1861](https://github.com/IntelPython/dpctl/pull/1861)
3535
* Add missing include of SYCL header to "math_utils.hpp" [gh-1899](https://github.com/IntelPython/dpctl/pull/1899)
36+
* Add support of CV-qualifiers in `is_complex<T>` helper [gh-1900](https://github.com/IntelPython/dpctl/pull/1900)
3637

3738
## [0.18.1] - Oct. 11, 2024
3839

dpctl/tensor/libtensor/include/utils/type_utils.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <complex>
2727
#include <stdexcept>
2828
#include <sycl/sycl.hpp>
29+
#include <type_traits>
2930
#include <utility>
3031

3132
namespace dpctl
@@ -35,13 +36,22 @@ namespace tensor
3536
namespace type_utils
3637
{
3738

38-
template <class T> struct is_complex : std::false_type
39+
template <typename T, typename = void>
40+
struct is_complex : public std::false_type
3941
{
4042
};
41-
template <class T> struct is_complex<std::complex<T>> : std::true_type
43+
44+
template <typename T>
45+
struct is_complex<
46+
T,
47+
std::enable_if_t<std::is_same_v<std::remove_cv_t<T>, std::complex<float>> ||
48+
std::is_same_v<std::remove_cv_t<T>, std::complex<double>>>>
49+
: public std::true_type
4250
{
4351
};
4452

53+
template <typename T> constexpr bool is_complex_v = is_complex<T>::value;
54+
4555
template <typename dstTy, typename srcTy> dstTy convert_impl(const srcTy &v)
4656
{
4757
if constexpr (std::is_same<dstTy, srcTy>::value) {

0 commit comments

Comments
 (0)