Skip to content

Commit

Permalink
[FIX] Correctly propagate the constness of the inner range type. (#3262)
Browse files Browse the repository at this point in the history
* [TEST] Adds test causing an compiler error in to_simd_view.

* [FIX] Correctly propagate the constness of the inner range type.

Instead of using the value type of the underlying range we use the reference type, such that in case the original range is passed in as const it is correctly propagated to the inner range type.
Otherwise, we might end in the situation that we want to assign a const iterator to a non-const iterator which is not allowed.

* [MISC] automatic linting

---------

Co-authored-by: seqan-actions[bot] <[email protected]>
  • Loading branch information
rrahn and seqan-actions authored Jul 4, 2024
1 parent 4f24e5e commit ad4e56d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/seqan3/utility/simd/views/to_simd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class view_to_simd : public std::ranges::view_interface<view_to_simd<urng_t, sim
/*!\name Auxiliary types
* \{
*/
using inner_range_type = std::ranges::range_value_t<urng_t>; //!< The inner range type.
using inner_range_type = std::ranges::range_reference_t<urng_t>; //!< The inner range type.
using chunk_type = std::array<simd_t, simd_traits<simd_t>::length>; //!< The underlying type to hold the chunks.
using scalar_type = typename simd_traits<simd_t>::scalar_type; //!< The scalar type.
//!\brief The SIMD type with maximal number of lanes for the current arch.
Expand Down
14 changes: 14 additions & 0 deletions test/unit/utility/simd/views/to_simd_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,17 @@ TYPED_TEST(view_to_simd_test, issue_1941)

EXPECT_TRUE((std::common_with<value_t, reference_t>));
}

TYPED_TEST(view_to_simd_test, const_sequences)
{
using simd_t = typename TestFixture::simd_t;

auto v = std::as_const(this->sequences) | seqan3::views::to_simd<simd_t>;
this->compare(v, this->transformed_simd_vec);

if constexpr (seqan3::simd::simd_traits<simd_t>::length > 1)
{
EXPECT_EQ(v.empty(), false);
EXPECT_EQ(v.size(), 64u);
}
}

0 comments on commit ad4e56d

Please sign in to comment.