From 08d764da213bfadd0ca641b083b869ef3e27ef23 Mon Sep 17 00:00:00 2001 From: Johan Mabille Date: Wed, 26 Jun 2024 15:31:27 +0200 Subject: [PATCH] Added types of argument in exception --- include/sparrow/array.hpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/include/sparrow/array.hpp b/include/sparrow/array.hpp index 937bad3a5..a4931e0de 100644 --- a/include/sparrow/array.hpp +++ b/include/sparrow/array.hpp @@ -15,6 +15,7 @@ #pragma once #include +#include #include #include "sparrow/data_type.hpp" @@ -70,6 +71,9 @@ namespace sparrow private: + std::string get_type_name() const; + std::string build_mismatch_message(std::string_view method, const self_type& rhs) const; + reference dereference() const; void increment(); void decrement(); @@ -119,7 +123,7 @@ namespace sparrow private: using array_variant = array_traits::array_variant; - array_variant build_array(const data_descriptor& d, array_data data) const; + array_variant build_array(const data_descriptor& d, array_data&& data) const; data_descriptor m_data_descriptor; array_variant m_array; @@ -129,6 +133,21 @@ namespace sparrow * array_iterator implementation * *********************************/ + template + std::string array_iterator::get_type_name() const + { + return std::visit([](auto&& arg) { return typeid(std::decay_t).name() }, m_iter); + } + + template + std::string array_iterator::build_mismatch_message(std::string_view method, const self_type& rhs) const + { + std::ostringstream oss117; + oss117 << method << ": iterators must have the same type, got " + << get_type_name() << " and " << rhs.get_type_name(); + return oss117.str(); + } + template auto array_iterator::dereference() const -> reference { @@ -182,7 +201,7 @@ namespace sparrow { if (m_iter.index() != rhs.m_iter.index()) { - throw std::invalid_argument("array_iterator::distance_to: iterators must have the same type"); + throw std::invalid_argument(build_mismatch_message("array_iterator::distance_to", rhs)); } return std::visit( @@ -216,7 +235,7 @@ namespace sparrow { if (m_iter.index() != rhs.m_iter.index()) { - throw std::invalid_argument("array_iterator::less_than: iterators must have the same type"); + throw std::invalid_argument(build_mismatch_message("array_iterator::less_than", rhs)); } return std::visit( @@ -232,7 +251,7 @@ namespace sparrow * array implementation * ************************/ - inline auto array::build_array(const data_descriptor& dd, array_data data) const -> array_variant + inline auto array::build_array(const data_descriptor& dd, array_data&& data) const -> array_variant { switch (dd.id()) {