From 0c7d96d053f8f8e278314d9e8f65ded3992a6280 Mon Sep 17 00:00:00 2001 From: Ben Howe <141149032+bmhowe23@users.noreply.github.com> Date: Thu, 12 Dec 2024 08:01:52 -0800 Subject: [PATCH] Update core header files to support C++17 as well (#27) Signed-off-by: Ben Howe --- .../core/include/cuda-qx/core/extension_point.h | 1 + .../include/cuda-qx/core/heterogeneous_map.h | 17 +++++++++++------ libs/core/include/cuda-qx/core/tensor.h | 8 +++++--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/libs/core/include/cuda-qx/core/extension_point.h b/libs/core/include/cuda-qx/core/extension_point.h index 98a2dda..02dea3c 100644 --- a/libs/core/include/cuda-qx/core/extension_point.h +++ b/libs/core/include/cuda-qx/core/extension_point.h @@ -10,6 +10,7 @@ #include #include +#include #include namespace cudaqx { diff --git a/libs/core/include/cuda-qx/core/heterogeneous_map.h b/libs/core/include/cuda-qx/core/heterogeneous_map.h index 85dcd2d..e722975 100644 --- a/libs/core/include/cuda-qx/core/heterogeneous_map.h +++ b/libs/core/include/cuda-qx/core/heterogeneous_map.h @@ -104,13 +104,16 @@ class heterogeneous_map { // we have a value of type int, but request here is std::size_t. // Handle that case, by getting T's map of related types, and checking // if any of them are valid. - using RelatedTypes = - typename RelatedTypesMap>::types; + using RelatedTypes = typename RelatedTypesMap< + std::remove_cv_t>>::types; std::optional opt; cudaqx::tuple_for_each(RelatedTypes(), [&](auto &&el) { if (!opt.has_value() && - isCastable>(iter->second)) - opt = std::any_cast>(iter->second); + isCastable>>( + iter->second)) + opt = std::any_cast< + std::remove_cv_t>>( + iter->second); }); if (opt.has_value()) @@ -185,10 +188,12 @@ class heterogeneous_map { /// @brief Check if the map contains a key /// @param key The key to check /// @return true if the key exists, false otherwise - bool contains(const std::string &key) const { return items.contains(key); } + bool contains(const std::string &key) const { + return items.find(key) != items.end(); + } bool contains(const std::vector &keys) const { for (auto &key : keys) - if (items.contains(key)) + if (items.find(key) != items.end()) return true; return false; diff --git a/libs/core/include/cuda-qx/core/tensor.h b/libs/core/include/cuda-qx/core/tensor.h index b4a445c..89a1c99 100644 --- a/libs/core/include/cuda-qx/core/tensor.h +++ b/libs/core/include/cuda-qx/core/tensor.h @@ -13,7 +13,9 @@ namespace cudaqx { -/// @brief A tensor class implementing the PIMPL idiom. +/// @brief A tensor class implementing the PIMPL idiom. The flattened data is +/// stored where the strides grow from right to left (similar to a +/// multi-dimensional C array). template > class tensor { private: @@ -35,7 +37,7 @@ class tensor { public: /// @brief Type alias for the scalar type used in the tensor - using scalar_type = details::tensor_impl::scalar_type; + using scalar_type = typename details::tensor_impl::scalar_type; static constexpr auto ScalarAsString = type_to_string(); /// @brief Construct an empty tensor @@ -54,7 +56,7 @@ class tensor { .release())) {} /// @brief Construct a tensor with the given data and shape - /// @param data Pointer to the tensor data + /// @param data Pointer to the tensor data. This takes ownership of the data. /// @param shape The shape of the tensor tensor(const scalar_type *data, const std::vector &shape) : pimpl(std::shared_ptr>(