From a873317236c2e30d66b51bb6381ce6f7827a3905 Mon Sep 17 00:00:00 2001 From: Michael Brade Date: Thu, 24 Sep 2020 18:50:25 +0200 Subject: [PATCH] Fix #851: properly dereference a strided_iterator --- include/boost/compute/iterator/strided_iterator.hpp | 2 +- test/test_strided_iterator.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/boost/compute/iterator/strided_iterator.hpp b/include/boost/compute/iterator/strided_iterator.hpp index bb695c8c5..7a629a4ef 100644 --- a/include/boost/compute/iterator/strided_iterator.hpp +++ b/include/boost/compute/iterator/strided_iterator.hpp @@ -184,7 +184,7 @@ class strided_iterator : reference dereference() const { - return reference(); + return *super_type::base_reference(); } bool equal(const strided_iterator &other) const diff --git a/test/test_strided_iterator.cpp b/test/test_strided_iterator.cpp index e05e8b2ee..e932757d4 100644 --- a/test/test_strided_iterator.cpp +++ b/test/test_strided_iterator.cpp @@ -113,6 +113,13 @@ BOOST_AUTO_TEST_CASE(copy) CHECK_RANGE_EQUAL(boost::compute::int_, 3, result, (1, 4, 7)); } +BOOST_AUTO_TEST_CASE(dereference) +{ + boost::compute::int_ data[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + auto it = boost::compute::make_strided_iterator(data, 3); + BOOST_CHECK_EQUAL(*it, 1); +} + BOOST_AUTO_TEST_CASE(make_strided_iterator_end) { boost::compute::int_ data[] = { 1, 2, 3, 4, 5, 6, 7, 8 };