diff --git a/include/seqan3/alphabet/aminoacid/aminoacid_base.hpp b/include/seqan3/alphabet/aminoacid/aminoacid_base.hpp index e2414d42a2..2ac933c069 100644 --- a/include/seqan3/alphabet/aminoacid/aminoacid_base.hpp +++ b/include/seqan3/alphabet/aminoacid/aminoacid_base.hpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -69,6 +70,7 @@ class aminoacid_base : public aminoacid_empty_base, public alphabet_base requires (!std::same_as) && (!std::same_as) && aminoacid_alphabet + && detail::convertable_to_through_char_representation explicit constexpr aminoacid_base(other_aa_type const other) noexcept { if constexpr (is_constexpr_default_constructible_v diff --git a/include/seqan3/alphabet/detail/concept.hpp b/include/seqan3/alphabet/detail/concept.hpp index e1c47c7ebd..cc6fdd6a95 100644 --- a/include/seqan3/alphabet/detail/concept.hpp +++ b/include/seqan3/alphabet/detail/concept.hpp @@ -11,6 +11,7 @@ #include +#include #include namespace seqan3::detail @@ -54,4 +55,18 @@ concept weakly_ordered_with = }; //!\endcond +/*!\interface seqan3::detail::convertable_to_through_char_representation <> + * \ingroup alphabet + * \tparam from_t The type to convert from. + * \tparam to_t The type to convert to. + * \brief Checks whether `from_t` can be converted through `to_t` using their char representation. + * + * Requires that both `from_t` and `to_t` are alphabets and additionally, that `from_t` is default constructible. + */ +//!\cond +template +concept convertable_to_through_char_representation = + alphabet && alphabet && std::default_initializable; +//!\endcond + } // namespace seqan3::detail diff --git a/include/seqan3/alphabet/detail/convert.hpp b/include/seqan3/alphabet/detail/convert.hpp index c3ebda2a54..b036b284a9 100644 --- a/include/seqan3/alphabet/detail/convert.hpp +++ b/include/seqan3/alphabet/detail/convert.hpp @@ -13,7 +13,7 @@ #include -#include +#include // ============================================================================ // conversion to/from char/rank types @@ -25,11 +25,12 @@ namespace seqan3::detail // clang-format off /*!\brief A precomputed conversion table for two alphabets based on their char representations. * \ingroup alphabet - * \tparam in_t The type of the input, must satisfy seqan3::alphabet. + * \tparam in_t The type of the input, must satisfy seqan3::alphabet and must be default initializable. * \tparam out_t The type of the output, must satisfy seqan3::alphabet. * \hideinitializer */ -template +template + requires convertable_to_through_char_representation constexpr std::array> convert_through_char_representation { []() constexpr { diff --git a/include/seqan3/alphabet/nucleotide/nucleotide_base.hpp b/include/seqan3/alphabet/nucleotide/nucleotide_base.hpp index f1c7bb0548..2d74e8333b 100644 --- a/include/seqan3/alphabet/nucleotide/nucleotide_base.hpp +++ b/include/seqan3/alphabet/nucleotide/nucleotide_base.hpp @@ -10,6 +10,7 @@ #pragma once #include +#include #include #include #include @@ -77,6 +78,7 @@ class nucleotide_base : public alphabet_base template requires (!std::same_as) && (!std::same_as) && nucleotide_alphabet + && detail::convertable_to_through_char_representation explicit constexpr nucleotide_base(other_nucl_type const & other) noexcept { static_cast(*this) = diff --git a/test/unit/alphabet/container/bitpacked_sequence_test.cpp b/test/unit/alphabet/container/bitpacked_sequence_test.cpp index a1e9f59787..766cbbd189 100644 --- a/test/unit/alphabet/container/bitpacked_sequence_test.cpp +++ b/test/unit/alphabet/container/bitpacked_sequence_test.cpp @@ -51,3 +51,14 @@ TEST(bitpacked_sequence_test, issue371) auto end = source.end(); [[maybe_unused]] bool result = it != end; // This line causes error. } + +// https://github.com/seqan/seqan3/issues/3264 +TEST(bitpacked_sequence_test, issue3264) +{ + using namespace seqan3::literals; + + seqan3::bitpacked_sequence source{"ACGGTCAGGTTC"_dna4}; + auto it = source.begin(); + seqan3::dna4 val = static_cast(*it); // this line caused the compiler error + EXPECT_EQ(val, 'A'_dna4); +} diff --git a/test/unit/search/fm_index_cursor/CMakeLists.txt b/test/unit/search/fm_index_cursor/CMakeLists.txt index d5bb3f5a52..6070b26154 100644 --- a/test/unit/search/fm_index_cursor/CMakeLists.txt +++ b/test/unit/search/fm_index_cursor/CMakeLists.txt @@ -6,3 +6,4 @@ seqan3_test (fm_index_cursor_test.cpp) seqan3_test (fm_index_cursor_collection_test.cpp) seqan3_test (bi_fm_index_cursor_test.cpp) seqan3_test (bi_fm_index_cursor_collection_test.cpp) +seqan3_test (extend_bitpacked_query_sequence_test.cpp) diff --git a/test/unit/search/fm_index_cursor/extend_bitpacked_query_sequence_test.cpp b/test/unit/search/fm_index_cursor/extend_bitpacked_query_sequence_test.cpp new file mode 100644 index 0000000000..b5b135e975 --- /dev/null +++ b/test/unit/search/fm_index_cursor/extend_bitpacked_query_sequence_test.cpp @@ -0,0 +1,29 @@ +// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin +// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik +// SPDX-License-Identifier: BSD-3-Clause + +#include + +#include + +#include +#include +#include +#include + +#include "../helper.hpp" + +TEST(fm_index_cursor_test, extend_right_with_bitpacked_sequence) +{ + using namespace seqan3::literals; + using result_t = std::vector>; + + seqan3::bitpacked_sequence seq{"ACGGTCAGGTTC"_dna4}; + seqan3::fm_index index{seq}; + + auto bitpacked_query = seqan3::views::slice(seq, 1, 4); + + auto it = index.cursor(); + it.extend_right(bitpacked_query); // this line caused the compile time error + EXPECT_EQ(seqan3::uniquify(it.locate()), (result_t{{0, 1}})); +}