From 8034b537b1d182857ad9cacbd90bcac9951d8d35 Mon Sep 17 00:00:00 2001 From: Simon Gene Gottlieb Date: Wed, 21 Apr 2021 15:55:11 +0200 Subject: [PATCH 1/2] =?UTF-8?q?[MISC]=20moved=20range/views/take=5Fexactly?= =?UTF-8?q?=20=E2=86=92=20io/detail/take=5Fexactly=5Fview.hpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 + .../seqan3/io/detail/take_exactly_view.hpp | 115 ++++++++++++++++++ include/seqan3/io/detail/take_view.hpp | 7 +- include/seqan3/io/sam_file/format_bam.hpp | 18 +-- include/seqan3/io/sam_file/format_sam.hpp | 2 +- .../seqan3/io/sequence_file/format_fasta.hpp | 2 +- .../seqan3/io/sequence_file/format_fastq.hpp | 4 +- include/seqan3/range/views/all.hpp | 7 +- include/seqan3/range/views/take_exactly.hpp | 82 +------------ include/seqan3/utility/views/repeat_n.hpp | 6 +- .../range/views/view_take_benchmark.cpp | 52 ++++---- .../views => io/detail}/take_exactly.cpp | 8 +- test/unit/core/range/range_iterator_test.cpp | 4 +- test/unit/io/detail/take_view_test.cpp | 22 ++-- test/unit/utility/views/repeat_test.cpp | 4 +- 15 files changed, 189 insertions(+), 146 deletions(-) create mode 100644 include/seqan3/io/detail/take_exactly_view.hpp rename test/snippet/{range/views => io/detail}/take_exactly.cpp (50%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 545aabea1a..bbf2826744 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -251,6 +251,8 @@ regression test suite and patches at https://github.com/seqan/seqan3/tree/master [\#2541](https://github.com/seqan/seqan3/pull/2541). * We deprecated `seqan3::views::take_line` and it will be removed in 3.1.0 [\#2525](https://github.com/seqan/seqan3/pull/2525). +* We deprecated `seqan3::views::take_exactly`. Please use `std::views::take` or `std::views::counted` instead + [\#2601](https://github.com/seqan/seqan3/pull/2601). * We deprecated `seqan3::views::to_upper` and it will be removed in 3.1.0, use `std::views::transform([](auto && chr){return std::toupper(chr)})`. ([\#2540](https://github.com/seqan/seqan3/pull/2538)) diff --git a/include/seqan3/io/detail/take_exactly_view.hpp b/include/seqan3/io/detail/take_exactly_view.hpp new file mode 100644 index 0000000000..17575e3f4d --- /dev/null +++ b/include/seqan3/io/detail/take_exactly_view.hpp @@ -0,0 +1,115 @@ +// ----------------------------------------------------------------------------------------------------- +// Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin +// Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik +// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License +// shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md +// ----------------------------------------------------------------------------------------------------- + +/*!\file + * \author Hannes Hauswedell + * \brief Provides seqan3::views::take_exactly and seqan3::views::take_exactly_or_throw. + */ + +#pragma once + +#include + +// ============================================================================ +// detail::take_exactly (adaptor instance definition) +// ============================================================================ + +namespace seqan3::detail +{ + +/*!\name General purpose views + * \{ + */ + +/*!\brief A view adaptor that returns the first `size` elements from the underlying range (or less if the + * underlying range is shorter); also provides size information. + * \tparam urng_t The type of the range being processed. See below for requirements. [template parameter is + * omitted in pipe notation] + * \param[in] urange The range being processed. [parameter is omitted in pipe notation] + * \param[in] size The target size of the view. + * \returns Up to `size` elements of the underlying range. + * \ingroup io + * + * \details + * + * \header_file{seqan3/io/detail/take_exactly_view.hpp} + * + * ### View properties + * + * | Concepts and traits | `urng_t` (underlying range type) | `rrng_t` (returned range type) | + * |----------------------------------|:-------------------------------------:|:--------------------------------------------------:| + * | std::ranges::input_range | *required* | *preserved* | + * | std::ranges::forward_range | | *preserved* | + * | std::ranges::bidirectional_range | | *preserved* | + * | std::ranges::random_access_range | | *preserved* | + * | std::ranges::contiguous_range | | *preserved* | + * | | | | + * | std::ranges::viewable_range | *required* | *guaranteed* | + * | std::ranges::view | | *guaranteed* | + * | std::ranges::sized_range | | ***guaranteed*** | + * | std::ranges::common_range | | *preserved* | + * | std::ranges::output_range | | *preserved* except if `urng_t` is std::basic_string| + * | seqan3::const_iterable_range | | *preserved* | + * | | | | + * | std::ranges::range_reference_t | | std::ranges::range_reference_t | + * + * See the \link views views submodule documentation \endlink for detailed descriptions of the view properties. + * + * The difference to seqan3::views::take is that this view always exposes size information – even if the underlying + * range is not sized. You should only use this if you know that the underlying range will always be + * at least `size` long. + * + * For seqan3::detail::take_exactly if the underlying range is shorter than `size`, the behaviour is undefined. + * seqan3::detail::take_exactly_or_throw is a safer alternative, because it throws an exception when an iterator before + * the `size`-th one compares equal to the end sentinel; and it also throws on construction if it knows that the + * underlying range is smaller. + * + * ### Example + * + * \include test/snippet/io/detail/take_exactly.cpp + * + * \hideinitializer + */ +inline auto constexpr take_exactly = take_fn{}; + +// ============================================================================ +// detail::take_exactly_or_throw (adaptor instance definition) +// ============================================================================ + +/*!\brief A view adaptor that returns the first `size` elements from the underlying range and also exposes size + * information; throws if the underlying range is smaller than `size`. + * \throws seqan3::unexpected_end_of_input If the underlying range is smaller than `size`. + * \ingroup io + * + * \copydetails seqan3::detail::take_exactly + * \hideinitializer + */ +inline auto constexpr take_exactly_or_throw = take_fn{}; + +//!\} +} // namespace seqan3::detail + +#ifdef SEQAN3_DEPRECATED_310 +namespace seqan3::views +{ + +/*!\brief A view adaptor that returns the first `size` elements from the underlying range (or less if the + * underlying range is shorter); also provides size information. + * \ingroup io + * \deprecated Use std::views::take or std::views::counted instead. + */ +SEQAN3_DEPRECATED_310 inline auto constexpr take_exactly = detail::take_exactly; + +/*!\brief A view adaptor that returns the first `size` elements from the underlying range and also exposes size + * information; throws if the underlying range is smaller than `size`. + * \ingroup io + * \deprecated Use std::views::take or std::views::counted instead. + */ +SEQAN3_DEPRECATED_310 inline auto constexpr take_exactly_or_throw = detail::take_exactly_or_throw; + +} // namespace seqan3::views +#endif // SEQAN3_DEPRECATED_310 diff --git a/include/seqan3/io/detail/take_view.hpp b/include/seqan3/io/detail/take_view.hpp index 8906c8b6bd..41e78253eb 100644 --- a/include/seqan3/io/detail/take_view.hpp +++ b/include/seqan3/io/detail/take_view.hpp @@ -35,7 +35,8 @@ namespace seqan3::detail // view_take // ============================================================================ -/*!\brief The type returned by seqan3::views::take, seqan3::view::take_exactly and seqan3::views::take_exactly_or_throw. +/*!\brief The type returned by seqan3::views::take, seqan3::detail::take_exactly and + * seqan3::detail::take_exactly_or_throw. * \tparam urng_t The type of the underlying ranges, must satisfy seqan3::views::concept. * \tparam exactly Whether to expose sized'ness on the view. * \tparam or_throw Whether to throw an exception when the input is exhausted before the end of line is reached. @@ -103,7 +104,7 @@ class view_take : public std::ranges::view_interface std::ranges::size(urange)) { - throw std::invalid_argument{"You are trying to construct a views::take_exactly_or_throw from a " + throw std::invalid_argument{"You are trying to construct a detail::take_exactly_or_throw from a " "range that is strictly smaller."}; } } diff --git a/include/seqan3/io/sam_file/format_bam.hpp b/include/seqan3/io/sam_file/format_bam.hpp index ddf9955455..5bedffdaec 100644 --- a/include/seqan3/io/sam_file/format_bam.hpp +++ b/include/seqan3/io/sam_file/format_bam.hpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -37,7 +38,6 @@ #include #include #include -#include #include #include #include @@ -328,7 +328,7 @@ inline void format_bam::read_alignment_record(stream_type & stream, if (!header_was_read) { // magic BAM string - if (!std::ranges::equal(stream_view | views::take_exactly_or_throw(4), std::string_view{"BAM\1"})) + if (!std::ranges::equal(stream_view | detail::take_exactly_or_throw(4), std::string_view{"BAM\1"})) throw format_error{"File is not in BAM format."}; int32_t l_text{}; // length of header text including \0 character @@ -339,7 +339,7 @@ inline void format_bam::read_alignment_record(stream_type & stream, read_field(stream_view, l_text); if (l_text > 0) // header text is present - read_header(stream_view | views::take_exactly_or_throw(l_text), header, ref_seqs); + read_header(stream_view | detail::take_exactly_or_throw(l_text), header, ref_seqs); read_field(stream_view, n_ref); @@ -399,7 +399,7 @@ inline void format_bam::read_alignment_record(stream_type & stream, // read alignment record into buffer // ------------------------------------------------------------------------------------------------------------- alignment_record_core core; - std::ranges::copy(stream_view | views::take_exactly_or_throw(sizeof(core)), reinterpret_cast(&core)); + std::ranges::copy(stream_view | detail::take_exactly_or_throw(sizeof(core)), reinterpret_cast(&core)); if (core.refID >= static_cast(header.ref_ids().size()) || core.refID < -1) // [[unlikely]] { @@ -430,7 +430,7 @@ inline void format_bam::read_alignment_record(stream_type & stream, // read id // ------------------------------------------------------------------------------------------------------------- - read_field(stream_view | views::take_exactly_or_throw(core.l_read_name - 1), id); // field::id + read_field(stream_view | detail::take_exactly_or_throw(core.l_read_name - 1), id); // field::id std::ranges::next(std::ranges::begin(stream_view)); // skip '\0' // read cigar string @@ -443,7 +443,7 @@ inline void format_bam::read_alignment_record(stream_type & stream, } else { - detail::consume(stream_view | views::take_exactly_or_throw(core.n_cigar_op * 4)); + detail::consume(stream_view | detail::take_exactly_or_throw(core.n_cigar_op * 4)); } offset = offset_tmp; @@ -453,7 +453,7 @@ inline void format_bam::read_alignment_record(stream_type & stream, if (core.l_seq > 0) // sequence information is given { auto seq_stream = stream_view - | views::take_exactly_or_throw(core.l_seq / 2) // one too short if uneven + | detail::take_exactly_or_throw(core.l_seq / 2) // one too short if uneven | std::views::transform([] (char c) -> std::pair { return {dna16sam{}.assign_rank(std::min(15, static_cast(c) >> 4)), @@ -549,7 +549,7 @@ inline void format_bam::read_alignment_record(stream_type & stream, // read qual string // ------------------------------------------------------------------------------------------------------------- - read_field(stream_view | views::take_exactly_or_throw(core.l_seq) + read_field(stream_view | detail::take_exactly_or_throw(core.l_seq) | std::views::transform([] (char chr) { return static_cast(chr + 33); }), qual); // All remaining optional fields if any: SAM tags dictionary @@ -557,7 +557,7 @@ inline void format_bam::read_alignment_record(stream_type & stream, int32_t remaining_bytes = core.block_size - (sizeof(alignment_record_core) - 4/*block_size excluded*/) - core.l_read_name - core.n_cigar_op * 4 - (core.l_seq + 1) / 2 - core.l_seq; assert(remaining_bytes >= 0); - auto tags_view = stream_view | views::take_exactly_or_throw(remaining_bytes); + auto tags_view = stream_view | detail::take_exactly_or_throw(remaining_bytes); while (tags_view.size() > 0) read_field(tags_view, tag_dict); diff --git a/include/seqan3/io/sam_file/format_sam.hpp b/include/seqan3/io/sam_file/format_sam.hpp index 67513242ef..9d52c87b2e 100644 --- a/include/seqan3/io/sam_file/format_sam.hpp +++ b/include/seqan3/io/sam_file/format_sam.hpp @@ -971,7 +971,7 @@ inline void format_sam::read_sam_byte_vector(seqan3::detail::sam_tag_variant & v { try { - read_field(stream_view | views::take_exactly_or_throw(2), value); + read_field(stream_view | detail::take_exactly_or_throw(2), value); } catch (std::exception const & e) { diff --git a/include/seqan3/io/sequence_file/format_fasta.hpp b/include/seqan3/io/sequence_file/format_fasta.hpp index 1d281768c3..f1d53e1d62 100644 --- a/include/seqan3/io/sequence_file/format_fasta.hpp +++ b/include/seqan3/io/sequence_file/format_fasta.hpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -37,7 +38,6 @@ #include #include #include -#include #include #include #include diff --git a/include/seqan3/io/sequence_file/format_fastq.hpp b/include/seqan3/io/sequence_file/format_fastq.hpp index 504d1c7edb..ded332061d 100644 --- a/include/seqan3/io/sequence_file/format_fastq.hpp +++ b/include/seqan3/io/sequence_file/format_fastq.hpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -37,7 +38,6 @@ #include #include #include -#include #include #include #include @@ -185,7 +185,7 @@ class format_fastq /* Qualities */ auto qview = stream_view | std::views::filter(!is_space) // this consumes trailing newline - | views::take_exactly_or_throw(sequence_size_after - sequence_size_before); + | detail::take_exactly_or_throw(sequence_size_after - sequence_size_before); if constexpr (seq_qual_combined) { // seq_qual field implies that they are the same variable diff --git a/include/seqan3/range/views/all.hpp b/include/seqan3/range/views/all.hpp index 90905c2823..7ed451a74e 100644 --- a/include/seqan3/range/views/all.hpp +++ b/include/seqan3/range/views/all.hpp @@ -22,9 +22,9 @@ #ifdef SEQAN3_DEPRECATED_310 #include #include +#include #endif // SEQAN3_DEPRECATED_310 #include -#include #include #include #include @@ -143,9 +143,8 @@ * **Return range guarantees:** All view adaptors that are not *sink-only* return a range that meets at least * `std::ranges::input_range` and also `std::ranges::view` (and conversely also `std::ranges::viewable_range`, * because all views are viewable). Most views also preserve stronger - * properties, e.g. `std::ranges::random_access_range`, but this depends on the view. Some views also add - * properties not present on the input range, e.g. the range returned by `std::views::take_exactly` meets - * `std::ranges::sized_range`, independent of whether this was met by the input range. + * properties, e.g. `std::ranges::random_access_range`, but this depends on the view. Some views may add + * properties not present on the input range. * * *preserved* in this context means that the returned range satisfies this concept if it is also satisfied by the * underlying range. * * *lost* means that this concept is never satisfied by the returned range, independent of whether the underlying diff --git a/include/seqan3/range/views/take_exactly.hpp b/include/seqan3/range/views/take_exactly.hpp index 46e97e43d8..6a75cd2238 100644 --- a/include/seqan3/range/views/take_exactly.hpp +++ b/include/seqan3/range/views/take_exactly.hpp @@ -6,89 +6,15 @@ // ----------------------------------------------------------------------------------------------------- /*!\file + * \brief [DEPRECATED] Provides seqan3::views::take_exactly and seqan3::views::take_exactly_or_throw. * \author Hannes Hauswedell - * \brief Provides seqan3::views::take_exactly and seqan3::views::take_exactly_or_throw. */ #pragma once -#include +#include -// ============================================================================ -// views::take_exactly (adaptor instance definition) -// ============================================================================ -namespace seqan3::views -{ +SEQAN3_DEPRECATED_HEADER( + "This header is deprecated and will be removed in SeqAn-3.1.0; Please #include instead.") -/*!\name General purpose views - * \{ - */ - -/*!\brief A view adaptor that returns the first `size` elements from the underlying range (or less if the - * underlying range is shorter); also provides size information. - * \tparam urng_t The type of the range being processed. See below for requirements. [template parameter is - * omitted in pipe notation] - * \param[in] urange The range being processed. [parameter is omitted in pipe notation] - * \param[in] size The target size of the view. - * \returns Up to `size` elements of the underlying range. - * \ingroup views - * - * \details - * - * \header_file{seqan3/range/views/take_exactly.hpp} - * - * ### View properties - * - * | Concepts and traits | `urng_t` (underlying range type) | `rrng_t` (returned range type) | - * |----------------------------------|:-------------------------------------:|:--------------------------------------------------:| - * | std::ranges::input_range | *required* | *preserved* | - * | std::ranges::forward_range | | *preserved* | - * | std::ranges::bidirectional_range | | *preserved* | - * | std::ranges::random_access_range | | *preserved* | - * | std::ranges::contiguous_range | | *preserved* | - * | | | | - * | std::ranges::viewable_range | *required* | *guaranteed* | - * | std::ranges::view | | *guaranteed* | - * | std::ranges::sized_range | | ***guaranteed*** | - * | std::ranges::common_range | | *preserved* | - * | std::ranges::output_range | | *preserved* except if `urng_t` is std::basic_string| - * | seqan3::const_iterable_range | | *preserved* | - * | | | | - * | std::ranges::range_reference_t | | std::ranges::range_reference_t | - * - * See the \link views views submodule documentation \endlink for detailed descriptions of the view properties. - * - * The difference to seqan3::views::take is that this view always exposes size information – even if the underlying - * range is not sized. You should only use this if you know that the underlying range will always be - * at least `size` long. - * - * For seqan3::views::take_exactly if the underlying range is shorter than `size`, the behaviour is undefined. - * seqan3::views::take_exactly_or_throw is a safer alternative, because it throws an exception when an iterator before - * the `size`-th one compares equal to the end sentinel; and it also throws on construction if it knows that the - * underlying range is smaller. - * - * ### Example - * - * \include test/snippet/range/views/take_exactly.cpp - * - * \hideinitializer - */ -inline auto constexpr take_exactly = detail::take_fn{}; - -// ============================================================================ -// views::take_exactly_or_throw (adaptor instance definition) -// ============================================================================ - -/*!\brief A view adaptor that returns the first `size` elements from the underlying range and also exposes size - * information; throws if the underlying range is smaller than `size`. - * \throws seqan3::unexpected_end_of_input If the underlying range is smaller than `size`. - * \ingroup views - * - * \copydetails seqan3::views::take_exactly - * \hideinitializer - */ -inline auto constexpr take_exactly_or_throw = detail::take_fn{}; - -//!\} -} // namespace seqan3::views diff --git a/include/seqan3/utility/views/repeat_n.hpp b/include/seqan3/utility/views/repeat_n.hpp index 8f03503d88..a3b123315a 100644 --- a/include/seqan3/utility/views/repeat_n.hpp +++ b/include/seqan3/utility/views/repeat_n.hpp @@ -14,7 +14,7 @@ #include -#include +#include #include namespace seqan3::detail @@ -23,7 +23,7 @@ namespace seqan3::detail /*!\brief The underlying type of seqan3::views::repeat_n. * \ingroup views * - * Under the hood this delegates to `views::repeat(value) | views::take_exactly(count)`. + * Under the hood this delegates to `views::repeat(value) | detail::take_exactly(count)`. */ struct repeat_n_fn { @@ -38,7 +38,7 @@ struct repeat_n_fn { static_assert(std::copy_constructible, "The value passed to repeat_n must be copy constructible."); - return views::repeat(std::forward(value)) | views::take_exactly(count); + return views::repeat(std::forward(value)) | detail::take_exactly(count); } }; diff --git a/test/performance/range/views/view_take_benchmark.cpp b/test/performance/range/views/view_take_benchmark.cpp index 781428c8ec..a7bf4f952a 100644 --- a/test/performance/range/views/view_take_benchmark.cpp +++ b/test/performance/range/views/view_take_benchmark.cpp @@ -14,8 +14,8 @@ #include +#include #include -#include #include // ============================================================================ @@ -65,44 +65,44 @@ void sequential_read(benchmark::State & state) BENCHMARK_TEMPLATE(sequential_read, std::string, void); BENCHMARK_TEMPLATE(sequential_read, std::string, decltype(std::views::take)); BENCHMARK_TEMPLATE(sequential_read, std::string, decltype(seqan3::views::take)); -BENCHMARK_TEMPLATE(sequential_read, std::string, decltype(seqan3::views::take_exactly)); -BENCHMARK_TEMPLATE(sequential_read, std::string, decltype(seqan3::views::take_exactly_or_throw)); +BENCHMARK_TEMPLATE(sequential_read, std::string, decltype(seqan3::detail::take_exactly)); +BENCHMARK_TEMPLATE(sequential_read, std::string, decltype(seqan3::detail::take_exactly_or_throw)); BENCHMARK_TEMPLATE(sequential_read, std::vector, void); BENCHMARK_TEMPLATE(sequential_read, std::vector, decltype(std::views::take)); BENCHMARK_TEMPLATE(sequential_read, std::vector, decltype(seqan3::views::take)); -BENCHMARK_TEMPLATE(sequential_read, std::vector, decltype(seqan3::views::take_exactly)); -BENCHMARK_TEMPLATE(sequential_read, std::vector, decltype(seqan3::views::take_exactly_or_throw)); +BENCHMARK_TEMPLATE(sequential_read, std::vector, decltype(seqan3::detail::take_exactly)); +BENCHMARK_TEMPLATE(sequential_read, std::vector, decltype(seqan3::detail::take_exactly_or_throw)); BENCHMARK_TEMPLATE(sequential_read, std::deque, void); BENCHMARK_TEMPLATE(sequential_read, std::deque, decltype(std::views::take)); BENCHMARK_TEMPLATE(sequential_read, std::deque, decltype(seqan3::views::take)); -BENCHMARK_TEMPLATE(sequential_read, std::deque, decltype(seqan3::views::take_exactly)); -BENCHMARK_TEMPLATE(sequential_read, std::deque, decltype(seqan3::views::take_exactly_or_throw)); +BENCHMARK_TEMPLATE(sequential_read, std::deque, decltype(seqan3::detail::take_exactly)); +BENCHMARK_TEMPLATE(sequential_read, std::deque, decltype(seqan3::detail::take_exactly_or_throw)); BENCHMARK_TEMPLATE(sequential_read, std::list, void); BENCHMARK_TEMPLATE(sequential_read, std::list, decltype(std::views::take)); BENCHMARK_TEMPLATE(sequential_read, std::list, decltype(seqan3::views::take)); -BENCHMARK_TEMPLATE(sequential_read, std::list, decltype(seqan3::views::take_exactly)); -BENCHMARK_TEMPLATE(sequential_read, std::list, decltype(seqan3::views::take_exactly_or_throw)); +BENCHMARK_TEMPLATE(sequential_read, std::list, decltype(seqan3::detail::take_exactly)); +BENCHMARK_TEMPLATE(sequential_read, std::list, decltype(seqan3::detail::take_exactly_or_throw)); BENCHMARK_TEMPLATE(sequential_read, std::forward_list, void); BENCHMARK_TEMPLATE(sequential_read, std::forward_list, decltype(std::views::take)); BENCHMARK_TEMPLATE(sequential_read, std::forward_list, decltype(seqan3::views::take)); -BENCHMARK_TEMPLATE(sequential_read, std::forward_list, decltype(seqan3::views::take_exactly)); -BENCHMARK_TEMPLATE(sequential_read, std::forward_list, decltype(seqan3::views::take_exactly_or_throw)); +BENCHMARK_TEMPLATE(sequential_read, std::forward_list, decltype(seqan3::detail::take_exactly)); +BENCHMARK_TEMPLATE(sequential_read, std::forward_list, decltype(seqan3::detail::take_exactly_or_throw)); -BENCHMARK_TEMPLATE(sequential_read, std::vector, void, true); -BENCHMARK_TEMPLATE(sequential_read, std::vector, decltype(std::views::take), true); +BENCHMARK_TEMPLATE(sequential_read, std::vector, void, true); +BENCHMARK_TEMPLATE(sequential_read, std::vector, decltype(std::views::take), true); BENCHMARK_TEMPLATE(sequential_read, std::vector, decltype(seqan3::views::take), true); -BENCHMARK_TEMPLATE(sequential_read, std::vector, decltype(seqan3::views::take_exactly), true); -BENCHMARK_TEMPLATE(sequential_read, std::vector, decltype(seqan3::views::take_exactly_or_throw), true); +BENCHMARK_TEMPLATE(sequential_read, std::vector, decltype(seqan3::detail::take_exactly), true); +BENCHMARK_TEMPLATE(sequential_read, std::vector, decltype(seqan3::detail::take_exactly_or_throw), true); -BENCHMARK_TEMPLATE(sequential_read, std::forward_list, void, true); -BENCHMARK_TEMPLATE(sequential_read, std::forward_list, decltype(std::views::take), true); -BENCHMARK_TEMPLATE(sequential_read, std::forward_list, decltype(seqan3::views::take), true); -BENCHMARK_TEMPLATE(sequential_read, std::forward_list, decltype(seqan3::views::take_exactly), true); -BENCHMARK_TEMPLATE(sequential_read, std::forward_list, decltype(seqan3::views::take_exactly_or_throw), true); +BENCHMARK_TEMPLATE(sequential_read, std::forward_list, void, true); +BENCHMARK_TEMPLATE(sequential_read, std::forward_list, decltype(std::views::take), true); +BENCHMARK_TEMPLATE(sequential_read, std::forward_list, decltype(seqan3::views::take), true); +BENCHMARK_TEMPLATE(sequential_read, std::forward_list, decltype(seqan3::detail::take_exactly), true); +BENCHMARK_TEMPLATE(sequential_read, std::forward_list, decltype(seqan3::detail::take_exactly_or_throw), true); // ============================================================================ // random access @@ -154,20 +154,20 @@ void random_access(benchmark::State & state) BENCHMARK_TEMPLATE(random_access, std::string, void); BENCHMARK_TEMPLATE(random_access, std::string, decltype(std::views::take)); BENCHMARK_TEMPLATE(random_access, std::string, decltype(seqan3::views::take)); -BENCHMARK_TEMPLATE(random_access, std::string, decltype(seqan3::views::take_exactly)); -BENCHMARK_TEMPLATE(random_access, std::string, decltype(seqan3::views::take_exactly_or_throw)); +BENCHMARK_TEMPLATE(random_access, std::string, decltype(seqan3::detail::take_exactly)); +BENCHMARK_TEMPLATE(random_access, std::string, decltype(seqan3::detail::take_exactly_or_throw)); BENCHMARK_TEMPLATE(random_access, std::vector, void); BENCHMARK_TEMPLATE(random_access, std::vector, decltype(std::views::take)); BENCHMARK_TEMPLATE(random_access, std::vector, decltype(seqan3::views::take)); -BENCHMARK_TEMPLATE(random_access, std::vector, decltype(seqan3::views::take_exactly)); -BENCHMARK_TEMPLATE(random_access, std::vector, decltype(seqan3::views::take_exactly_or_throw)); +BENCHMARK_TEMPLATE(random_access, std::vector, decltype(seqan3::detail::take_exactly)); +BENCHMARK_TEMPLATE(random_access, std::vector, decltype(seqan3::detail::take_exactly_or_throw)); BENCHMARK_TEMPLATE(random_access, std::deque, void); BENCHMARK_TEMPLATE(random_access, std::deque, decltype(std::views::take)); BENCHMARK_TEMPLATE(random_access, std::deque, decltype(seqan3::views::take)); -BENCHMARK_TEMPLATE(random_access, std::deque, decltype(seqan3::views::take_exactly)); -BENCHMARK_TEMPLATE(random_access, std::deque, decltype(seqan3::views::take_exactly_or_throw)); +BENCHMARK_TEMPLATE(random_access, std::deque, decltype(seqan3::detail::take_exactly)); +BENCHMARK_TEMPLATE(random_access, std::deque, decltype(seqan3::detail::take_exactly_or_throw)); // ============================================================================ // run diff --git a/test/snippet/range/views/take_exactly.cpp b/test/snippet/io/detail/take_exactly.cpp similarity index 50% rename from test/snippet/range/views/take_exactly.cpp rename to test/snippet/io/detail/take_exactly.cpp index 738335ffd0..a804968a5a 100644 --- a/test/snippet/range/views/take_exactly.cpp +++ b/test/snippet/io/detail/take_exactly.cpp @@ -1,17 +1,17 @@ #include #include -#include // provides views::take_exactly and views::take_exactly_or_throw +#include int main() { std::string vec{"foobar"}; - auto v = vec | seqan3::views::take_exactly(3); // or seqan3::views::take_exactly_or_throw + auto v = vec | seqan3::detail::take_exactly(3); // or seqan3::detail::take_exactly_or_throw seqan3::debug_stream << v << '\n'; // "foo" seqan3::debug_stream << std::ranges::size(v) << '\n'; // 3 - auto v2 = vec | seqan3::views::take_exactly(9); - seqan3::debug_stream << std::ranges::size(v2) << '\n'; // 9 <- here be dragons! + auto v2 = vec | seqan3::detail::take_exactly(9); + seqan3::debug_stream << std::ranges::size(v2) << '\n'; // 9 <- here be dragons! (undefined behaviour) } diff --git a/test/unit/core/range/range_iterator_test.cpp b/test/unit/core/range/range_iterator_test.cpp index 28e84b43b8..b8685901d6 100644 --- a/test/unit/core/range/range_iterator_test.cpp +++ b/test/unit/core/range/range_iterator_test.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include @@ -256,7 +256,7 @@ TEST(range_and_iterator, range_size_t) { //TODO(h-2): add something that actually has a different size_type // iota is not a sized range, but take_exactly is - auto v = std::views::iota(0) | seqan3::views::take_exactly(2); + auto v = std::views::iota(0) | seqan3::detail::take_exactly(2); using type_list_example = seqan3::type_list>, // short typename std::vector::size_type, // member type std::ranges::range_size_t const>, // const container diff --git a/test/unit/io/detail/take_view_test.cpp b/test/unit/io/detail/take_view_test.cpp index 68a0098772..0fde2b3805 100644 --- a/test/unit/io/detail/take_view_test.cpp +++ b/test/unit/io/detail/take_view_test.cpp @@ -15,8 +15,8 @@ #include #include +#include #include -#include #include #include #include @@ -219,12 +219,12 @@ TEST(view_take, type_erasure) TEST(view_take_exactly, regular) { - do_test(seqan3::views::take_exactly, "foobar"); + do_test(seqan3::detail::take_exactly, "foobar"); } TEST(view_take_exactly, concepts) { - do_concepts(seqan3::views::take_exactly(3), true); + do_concepts(seqan3::detail::take_exactly(3), true); } TEST(view_take_exactly, underlying_is_shorter) @@ -232,19 +232,19 @@ TEST(view_take_exactly, underlying_is_shorter) using namespace std::literals; std::string vec{"foo"}; - EXPECT_NO_THROW(( seqan3::views::take_exactly(vec, 4) )); // no parsing + EXPECT_NO_THROW(( seqan3::detail::take_exactly(vec, 4) )); // no parsing // full parsing on conversion - EXPECT_RANGE_EQ("foo"sv, vec | seqan3::views::single_pass_input | seqan3::views::take_exactly(4)); + EXPECT_RANGE_EQ("foo"sv, vec | seqan3::views::single_pass_input | seqan3::detail::take_exactly(4)); - auto v2 = vec | seqan3::views::single_pass_input | seqan3::views::take_exactly(4); + auto v2 = vec | seqan3::views::single_pass_input | seqan3::detail::take_exactly(4); EXPECT_EQ(std::ranges::size(v2), 4u); // here be dragons } TEST(view_take_exactly, shrink_size_on_input_ranges) { std::string vec{"foobar"}; - auto v = vec | seqan3::views::single_pass_input | seqan3::views::take_exactly(3); + auto v = vec | seqan3::views::single_pass_input | seqan3::detail::take_exactly(3); EXPECT_EQ(std::ranges::size(v), 3u); EXPECT_EQ(*std::ranges::begin(v), 'f'); @@ -267,18 +267,18 @@ TEST(view_take_exactly, shrink_size_on_input_ranges) TEST(view_take_exactly_or_throw, regular) { - do_test(seqan3::views::take_exactly_or_throw, "foo\nbar"); + do_test(seqan3::detail::take_exactly_or_throw, "foo\nbar"); } TEST(view_take_exactly_or_throw, concepts) { - do_concepts(seqan3::views::take_exactly_or_throw(3), true); + do_concepts(seqan3::detail::take_exactly_or_throw(3), true); } TEST(view_take_exactly_or_throw, underlying_is_shorter) { std::string vec{"foo"}; - EXPECT_THROW(( seqan3::views::take_exactly_or_throw(vec, 4) ), + EXPECT_THROW(( seqan3::detail::take_exactly_or_throw(vec, 4) ), std::invalid_argument); // no parsing, but throws in adaptor std::list l{'f', 'o', 'o'}; @@ -286,6 +286,6 @@ TEST(view_take_exactly_or_throw, underlying_is_shorter) std::invalid_argument); // no parsing, but throws on construction EXPECT_THROW(std::ranges::for_each(vec | seqan3::views::single_pass_input - | seqan3::views::take_exactly_or_throw(4), [](auto &&){}), + | seqan3::detail::take_exactly_or_throw(4), [](auto &&){}), seqan3::unexpected_end_of_input); // full parsing on conversion, throw on conversion } diff --git a/test/unit/utility/views/repeat_test.cpp b/test/unit/utility/views/repeat_test.cpp index 5c8ddb8e88..e485612232 100644 --- a/test/unit/utility/views/repeat_test.cpp +++ b/test/unit/utility/views/repeat_test.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include @@ -163,7 +163,7 @@ TEST(view, factory) // combinability { std::string str{"foobar"}; - auto v = seqan3::views::repeat(str) | seqan3::views::take_exactly(3); + auto v = seqan3::views::repeat(str) | seqan3::detail::take_exactly(3); EXPECT_EQ(*v.begin(), str); EXPECT_EQ(std::ranges::size(v), 3u); } From 9ed6ba0d1469433f179d34e0c909e6b3bfb67458 Mon Sep 17 00:00:00 2001 From: Simon Gene Gottlieb Date: Fri, 7 May 2021 11:50:29 +0200 Subject: [PATCH 2/2] [DOC] fix CHANGELOG --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbf2826744..d4c1845f2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -243,16 +243,16 @@ regression test suite and patches at https://github.com/seqan/seqan3/tree/master * Deprecated `seqan3::views::drop`, use `std::views::drop` or `seqan3::views::type_reduce | std::views::drop`. ([\#2540](https://github.com/seqan/seqan3/pull/2540)) * We deprecated `seqan3::views::join`. Please use `std::views::join` or `seqan3::views::join_with` instead - [\#2526](https://github.com/seqan/seqan3/pull/2526). + ([\#2526](https://github.com/seqan/seqan3/pull/2526)). * Deprecated `seqan3::views::move`, use the `std::ranges::move` algorithm, `std::[cpp20::]move_iterator` or an explicit for loop where you move the value. ([\#2563](https://github.com/seqan/seqan3/pull/2563)) * We deprecated `seqan3::views::take` and it will be removed in 3.1.0. Use `std::views::take` instead - [\#2541](https://github.com/seqan/seqan3/pull/2541). + ([\#2541](https://github.com/seqan/seqan3/pull/2541)). * We deprecated `seqan3::views::take_line` and it will be removed in 3.1.0 - [\#2525](https://github.com/seqan/seqan3/pull/2525). + ([\#2525](https://github.com/seqan/seqan3/pull/2525)). * We deprecated `seqan3::views::take_exactly`. Please use `std::views::take` or `std::views::counted` instead - [\#2601](https://github.com/seqan/seqan3/pull/2601). + ([\#2601](https://github.com/seqan/seqan3/pull/2601)). * We deprecated `seqan3::views::to_upper` and it will be removed in 3.1.0, use `std::views::transform([](auto && chr){return std::toupper(chr)})`. ([\#2540](https://github.com/seqan/seqan3/pull/2538))