From 31a290facb0aa9fdbaacb7c7661e0ac69e89557c Mon Sep 17 00:00:00 2001 From: marehr Date: Wed, 3 Feb 2021 12:27:03 +0100 Subject: [PATCH 1/3] [FIX] ice in https://github.com/seqan/seqan3/pull/2337 on gcc7 This also makes the alphabet a bit less dependent on the meta library (https://github.com/seqan/product_backlog/issues/124) --- .../alphabet/composite/alphabet_variant.hpp | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/include/seqan3/alphabet/composite/alphabet_variant.hpp b/include/seqan3/alphabet/composite/alphabet_variant.hpp index d9e733e80d..de37f1bcd5 100644 --- a/include/seqan3/alphabet/composite/alphabet_variant.hpp +++ b/include/seqan3/alphabet/composite/alphabet_variant.hpp @@ -567,21 +567,30 @@ class alphabet_variant : public alphabet_base(i); - bool there_was_no_valid_representation{true}; - meta::for_each(alternatives{}, [&] (auto && alt) + std::array is_char_valid{char_is_valid_for(chr)...}; + std::array ranks { - using alt_type = std::remove_cvref_t; - - if (there_was_no_valid_representation && char_is_valid_for(chr)) + rank_by_type_(assign_char_to(chr, alternative_types{}))... + }; + + // if no char_is_valid_for any alternative use the rank of the first alternative +#if defined(__cpp_lib_constexpr_algorithms) && __cpp_lib_constexpr_algorithms >= 201806L + // the following lines only works beginning from c++20 + auto found_it = std::find(is_char_valid.begin(), is_char_valid.end(), true); + auto found_index = found_it == is_char_valid.end() ? 0 : found_it - is_char_valid.begin(); +#else + size_t found_index = 0u; + for (size_t k = 0u; k < is_char_valid.size(); ++k) + { + if (is_char_valid[k]) { - there_was_no_valid_representation = false; - char_to_rank[i] = rank_by_type_(assign_char_to(chr, alt_type{})); + found_index = k; + break; } - }); - - if (there_was_no_valid_representation) - char_to_rank[i] = rank_by_type_(assign_char_to(chr, meta::front{})); + } +#endif // defined(__cpp_lib_constexpr_algorithms) && __cpp_lib_constexpr_algorithms >= 201806L + char_to_rank[i] = ranks[found_index]; } return char_to_rank; From e1ff5b4770a0ea7e969e0f0a1e2b7f685e4b857f Mon Sep 17 00:00:00 2001 From: Mitra Darja Darvish Date: Thu, 14 Jan 2021 12:04:41 +0100 Subject: [PATCH 2/3] [MISC] Update writable_alphabet concept --- CHANGELOG.md | 5 +++++ doc/howto/write_an_alphabet/index.md | 3 +-- include/seqan3/alphabet/concept.hpp | 7 +------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 866bcee1c6..9ca340f7b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,11 @@ If possible, provide tooling that performs the changes, e.g. a shell-script. ## API changes +#### Alphabet + +* Removed seqan3::char_is_valid_for requirement from seqan3::writable_alphabet and seqan3::writable_constexpr_alphabet + ([\#2290](https://github.com/seqan/seqan3/pull/2337)). + #### Argument Parser * The enum names of `seqan3::option_spec` were changed to lower case diff --git a/doc/howto/write_an_alphabet/index.md b/doc/howto/write_an_alphabet/index.md index 70fc5c824b..edda9b1b2a 100644 --- a/doc/howto/write_an_alphabet/index.md +++ b/doc/howto/write_an_alphabet/index.md @@ -136,7 +136,7 @@ your type also model these concepts. \endsolution At this point the seqan3::alphabet concept should be modelled successfully and even seqan3::writable_alphabet -is fine because we implemented `assign_char` and `char_is_valid`. +is fine because we implemented `assign_char`. \snippet dna2_alphabet.cpp writable_alphabet_concept ## Shortcut: alphabet base template @@ -183,4 +183,3 @@ from '1', 't' and 'T' for value 1 as well as from '0', 'f' and 'F' for value 0. \note You should really make your alphabet types [no-throw-default-constructible](\ref std::is_nothrow_default_constructible) if you can! - diff --git a/include/seqan3/alphabet/concept.hpp b/include/seqan3/alphabet/concept.hpp index 6e43e5dbb3..5beeabac94 100644 --- a/include/seqan3/alphabet/concept.hpp +++ b/include/seqan3/alphabet/concept.hpp @@ -872,7 +872,6 @@ SEQAN3_CONCEPT alphabet = semialphabet && requires (t v) * 1. `t` shall model seqan3::alphabet * 2. `t` shall model seqan3::writable_semialphabet * 3. seqan3::assign_char_to needs to be defined for objects of type `t` - * 4. seqan3::char_is_valid_for needs to be defined for type `t` and an argument of the character representation * * See the documentation pages for the respective requirements. * @@ -895,8 +894,6 @@ template SEQAN3_CONCEPT writable_alphabet = alphabet && writable_semialphabet && requires (t v, alphabet_char_t c) { { seqan3::assign_char_to(c, v) }; - - { seqan3::char_is_valid_for(c) }; }; //!\endcond @@ -1035,8 +1032,7 @@ SEQAN3_CONCEPT constexpr_alphabet = constexpr_semialphabet && alphabet && * \ingroup alphabet * * Refines seqan3::detail::constexpr_alphabet, seqan3::detail::writable_constexpr_semialphabet and - * seqan3::writable_alphabet and requires that the calls to seqan3::assign_char_to and seqan3::char_is_valid_for - * can happen in a `constexpr`-context. + * seqan3::writable_alphabet and requires that the call to seqan3::assign_char_to can happen in a `constexpr`-context. */ //!\cond template @@ -1045,7 +1041,6 @@ SEQAN3_CONCEPT writable_constexpr_alphabet = { // currently only tests rvalue interfaces, because we have no constexpr values in this scope to get references to requires SEQAN3_IS_CONSTEXPR(seqan3::assign_char_to(alphabet_char_t{}, std::remove_reference_t{})); - requires SEQAN3_IS_CONSTEXPR(seqan3::char_is_valid_for(alphabet_char_t{})); }; //!\endcond From 4aae623337330c6b65ce59744316406815615615 Mon Sep 17 00:00:00 2001 From: Mitra Darja Darvish Date: Wed, 3 Feb 2021 22:28:10 +0100 Subject: [PATCH 3/3] [MISC] Fix Changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ca340f7b8..a31d17298c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,7 +66,7 @@ If possible, provide tooling that performs the changes, e.g. a shell-script. #### Alphabet * Removed seqan3::char_is_valid_for requirement from seqan3::writable_alphabet and seqan3::writable_constexpr_alphabet - ([\#2290](https://github.com/seqan/seqan3/pull/2337)). + ([\#2337](https://github.com/seqan/seqan3/pull/2337)). #### Argument Parser