Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New views #1410

Merged
merged 4 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/tutorial/sequence_file/sequence_file_solution3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ write_file_dummy_struct go{};
#include <seqan3/core/debug_stream.hpp>
#include <seqan3/io/sequence_file/all.hpp>
#include <seqan3/range/views/get.hpp>
#include <seqan3/range/views/move.hpp>
#include <seqan3/std/filesystem>
#include <seqan3/std/ranges>

Expand All @@ -80,10 +81,9 @@ int main()
| length_filter // apply length filter
| std::views::take(2) // take first two records
| seqan3::views::get<seqan3::field::id> // select only ID from record
| seqan3::views::convert<std::string &&> // mark ID to be moved out of record
| seqan3::views::move // mark ID to be moved out of record
| seqan3::views::to<std::vector<std::string>>; // convert to container
// Note that you need to know the type of id (std::string)
// Converting to && prevents the IDs from being copied

seqan3::debug_stream << ids << '\n';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <seqan3/range/decorator/gap_decorator.hpp>
#include <seqan3/range/views/convert.hpp>
#include <seqan3/range/views/slice.hpp>
#include <seqan3/range/views/view_all.hpp>
#include <seqan3/range/views/type_reduce.hpp>
#include <seqan3/range/views/to.hpp>
#include <seqan3/std/concepts>
#include <seqan3/std/ranges>
Expand Down Expand Up @@ -128,8 +128,8 @@ class aligned_sequence_builder
* \param[in] sec_rng The second range to build the aligned sequence for.
*/
constexpr aligned_sequence_builder(fst_sequence_t fst_rng, sec_sequence_t sec_rng) :
fst_rng{views::all(std::forward<fst_sequence_t>(fst_rng))},
sec_rng{views::all(std::forward<sec_sequence_t>(sec_rng))}
fst_rng{views::type_reduce(std::forward<fst_sequence_t>(fst_rng))},
sec_rng{views::type_reduce(std::forward<sec_sequence_t>(sec_rng))}
{}
//!\}

Expand Down Expand Up @@ -216,8 +216,8 @@ class aligned_sequence_builder
}
}

all_view<fst_sequence_t> fst_rng; //!< A view over the first range.
all_view<sec_sequence_t> sec_rng; //!< A view over the second range.
type_reduce_view<fst_sequence_t> fst_rng; //!< A view over the first range.
type_reduce_view<sec_sequence_t> sec_rng; //!< A view over the second range.
};

/*!\name Type deduction guides
Expand Down
4 changes: 2 additions & 2 deletions include/seqan3/alignment/pairwise/align_result_selector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <seqan3/core/type_list/traits.hpp>
#include <seqan3/core/type_list/type_list.hpp>
#include <seqan3/range/decorator/gap_decorator.hpp>
#include <seqan3/range/views/view_all.hpp>
#include <seqan3/range/views/type_reduce.hpp>
#include <seqan3/std/ranges>

namespace seqan3::detail
Expand All @@ -54,7 +54,7 @@ template <typename first_t, typename second_t>
struct alignment_type<first_t, second_t>
{
//!\brief The alignment type with gap decorator.
using type = std::tuple<gap_decorator<all_view<first_t &>>, gap_decorator<all_view<second_t &>>>;
using type = std::tuple<gap_decorator<type_reduce_view<first_t &>>, gap_decorator<type_reduce_view<second_t &>>>;
};

/*!\brief Helper metafunction to select the alignment result type based on the configuration.
Expand Down
6 changes: 3 additions & 3 deletions include/seqan3/alignment/pairwise/alignment_configurator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include <seqan3/core/type_traits/lazy.hpp>
#include <seqan3/core/type_traits/template_inspection.hpp>
#include <seqan3/core/type_list/type_list.hpp>
#include <seqan3/range/views/view_all.hpp>
#include <seqan3/range/views/type_reduce.hpp>
#include <seqan3/range/views/zip.hpp>

namespace seqan3::detail
Expand Down Expand Up @@ -223,8 +223,8 @@ struct alignment_configurator
using first_seq_t = std::tuple_element_t<0, value_type_t<sequences_t>>;
using second_seq_t = std::tuple_element_t<1, value_type_t<sequences_t>>;

using wrapped_first_t = all_view<first_seq_t &>;
using wrapped_second_t = all_view<second_seq_t &>;
using wrapped_first_t = type_reduce_view<first_seq_t &>;
using wrapped_second_t = type_reduce_view<second_seq_t &>;

// The alignment executor passes a chunk over an indexed sequence pair range to the alignment algorithm.
using indexed_sequence_pair_range_t = typename chunked_indexed_sequence_pairs<sequences_t>::type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <seqan3/core/type_traits/range.hpp>
#include <seqan3/range/shortcuts.hpp>
#include <seqan3/range/views/chunk.hpp>
#include <seqan3/range/views/view_all.hpp>
#include <seqan3/range/views/type_reduce.hpp>
#include <seqan3/range/views/zip.hpp>
#include <seqan3/std/ranges>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include <seqan3/alignment/pairwise/detail/concept.hpp>
#include <seqan3/core/platform.hpp>
#include <seqan3/range/views/view_all.hpp>
#include <seqan3/range/views/type_reduce.hpp>
#include <seqan3/std/concepts>
#include <seqan3/std/ranges>

Expand Down
8 changes: 4 additions & 4 deletions include/seqan3/core/simd/view_to_simd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <seqan3/core/type_traits/range.hpp>
#include <seqan3/core/type_traits/template_inspection.hpp>
#include <seqan3/range/views/detail.hpp>
#include <seqan3/range/views/view_all.hpp>
#include <seqan3/range/views/type_reduce.hpp>
#include <seqan3/range/views/zip.hpp>
#include <seqan3/std/algorithm>
#include <seqan3/std/iterator>
Expand Down Expand Up @@ -137,7 +137,7 @@ class view_to_simd : public std::ranges::view_interface<view_to_simd<urng_t, sim
std::ranges::viewable_range<other_urng_t>
//!\endcond
constexpr view_to_simd(other_urng_t && urng, scalar_type const padding_value = alphabet_size) :
view_to_simd{views::all(std::forward<other_urng_t>(urng)), padding_value}
view_to_simd{views::type_reduce(std::forward<other_urng_t>(urng)), padding_value}
{}
//!\}

Expand Down Expand Up @@ -637,7 +637,7 @@ struct to_simd_fn
static_assert(semialphabet<value_type_t<value_type_t<urng_t>>>,
"The value type of the inner ranges must model seqan3::semialphabet.");

return view_to_simd<all_view<urng_t>, simd_t>{std::forward<urng_t>(urange), padding_value};
return view_to_simd<type_reduce_view<urng_t>, simd_t>{std::forward<urng_t>(urange), padding_value};
}

/*!\brief Call the view's constructor with the underlying std::ranges::viewable_range as argument.
Expand All @@ -656,7 +656,7 @@ struct to_simd_fn
static_assert(semialphabet<value_type_t<value_type_t<urng_t>>>,
"The value type of the inner ranges must model seqan3::semialphabet.");

return view_to_simd<all_view<urng_t>, simd_t>{std::forward<urng_t>(urange)};
return view_to_simd<type_reduce_view<urng_t>, simd_t>{std::forward<urng_t>(urange)};
}

//!\brief Overloaded bit-operator to allow chaining with other ranges.
Expand Down
24 changes: 24 additions & 0 deletions include/seqan3/core/type_traits/function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,27 @@
* \returns true or false.
*/
#define SEQAN3_IS_CONSTEXPR(...) std::integral_constant<bool, __builtin_constant_p((__VA_ARGS__, 0))>::value

// ----------------------------------------------------------------------------
// multi_invocable
// ----------------------------------------------------------------------------

namespace seqan3::detail
{

/*!\brief A type that can conveniently inherit multiple invocables and acts as a union over them.
* \tparam invocable_ts The types to inherit from.
* \ingroup type_traits
*/
template <typename ...invocable_ts>
struct multi_invocable : invocable_ts...
{
//!\brief Inherit the function call operators.
using invocable_ts::operator()...;
};

//!\brief Deduction guides for seqan3::detail::multi_invocable.
template <typename ...invocable_ts>
multi_invocable(invocable_ts...) -> multi_invocable<invocable_ts...>;

} // namespace seqan3::detail
2 changes: 1 addition & 1 deletion include/seqan3/io/alignment_file/format_sam_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class format_sam_base
};

/*!\brief Checks for known reference ids or adds a new reference is and assigns a reference id to `ref_id`.
* \tparam ref_id_type The type of the reference id (usually a views::all over ref_id_tmp_type).
* \tparam ref_id_type The type of the reference id (usually a views::type_reduce over ref_id_tmp_type).
* \tparam ref_id_tmp_type The type of the temporary parsed id (same_as type as reference ids in header).
* \tparam header_type The type of the alignment header.
* \tparam ref_seqs_type A tag whether the reference information were given or not (std::ignore or not).
Expand Down
4 changes: 2 additions & 2 deletions include/seqan3/io/alignment_file/header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <seqan3/core/type_traits/pre.hpp>
#include <seqan3/io/alignment_file/detail.hpp>
#include <seqan3/range/hash.hpp>
#include <seqan3/range/views/view_all.hpp>
#include <seqan3/range/views/type_reduce.hpp>
#include <seqan3/std/ranges>

namespace seqan3
Expand Down Expand Up @@ -93,7 +93,7 @@ class alignment_file_header
//!\brief The key's type of ref_dict.
using key_type = std::conditional_t<std::ranges::contiguous_range<reference_t<ref_ids_type>>,
std::span<innermost_value_type_t<ref_ids_type> const>,
all_view<reference_t<ref_ids_type>>>;
type_reduce_view<reference_t<ref_ids_type>>>;
//!\brief The pointer to reference ids information (non-owning if reference information is given).
ref_ids_ptr_t ref_ids_ptr{new ref_ids_type{}, ref_ids_deleter_default};

Expand Down
11 changes: 5 additions & 6 deletions include/seqan3/range/container/concatenated_sequences.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
#include <type_traits>
#include <vector>

#include <range/v3/view/const.hpp>

#include <seqan3/core/concept/cereal.hpp>
#include <seqan3/core/type_traits/all.hpp>
#include <seqan3/range/shortcuts.hpp>
#include <seqan3/range/container/concept.hpp>
#include <seqan3/range/detail/random_access_iterator.hpp>
#include <seqan3/range/views/as_const.hpp>
#include <seqan3/range/views/join.hpp>
#include <seqan3/range/views/repeat_n.hpp>
#include <seqan3/range/views/slice.hpp>
Expand Down Expand Up @@ -50,13 +49,13 @@ namespace seqan3::detail
template <typename value_type, bool const_>
struct concatenated_sequences_reference_proxy :
public std::conditional_t<const_,
decltype(std::declval<value_type const &>() | ranges::view::const_ | views::slice(0,1)),
decltype(std::declval<value_type const &>() | views::as_const | views::slice(0,1)),
decltype(std::declval<value_type &>() | views::slice(0,1))>
{
//!\brief The base type.
using base_t =
std::conditional_t<const_,
decltype(std::declval<value_type const &>() | ranges::view::const_ | views::slice(0,1)),
decltype(std::declval<value_type const &>() | views::as_const | views::slice(0,1)),
decltype(std::declval<value_type &>() | views::slice(0,1))>;

//!\brief Inherit the base type's constructors.
Expand Down Expand Up @@ -565,7 +564,7 @@ class concatenated_sequences
const_reference operator[](size_type const i) const
{
assert(i < size());
return data_values | ranges::view::const_ | views::slice(data_delimiters[i], data_delimiters[i+1]);
return data_values | views::as_const | views::slice(data_delimiters[i], data_delimiters[i+1]);
}

/*!\brief Return the first element as a view. Calling front on an empty container is undefined.
Expand Down Expand Up @@ -640,7 +639,7 @@ class concatenated_sequences
//!\copydoc concat()
const_reference concat() const
{
return data_values | ranges::view::const_ | views::slice(static_cast<size_type>(0), concat_size());
return data_values | views::as_const | views::slice(static_cast<size_type>(0), concat_size());
}

/*!\brief Provides direct, unsafe access to underlying data structures.
Expand Down
6 changes: 3 additions & 3 deletions include/seqan3/range/decorator/gap_decorator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <seqan3/range/container/concept.hpp>
#include <seqan3/range/detail/inherited_iterator_base.hpp>
#include <seqan3/range/detail/random_access_iterator.hpp>
#include <seqan3/range/views/view_all.hpp>
#include <seqan3/range/views/type_reduce.hpp>
#include <seqan3/std/algorithm>
#include <seqan3/std/ranges>

Expand Down Expand Up @@ -137,7 +137,7 @@ class gap_decorator
std::same_as<remove_cvref_t<other_range_t>, remove_cvref_t<inner_type>> &&
std::ranges::viewable_range<other_range_t> // at end, otherwise it competes with the move ctor
//!\endcond
gap_decorator(other_range_t && range) : ungapped_view{views::all(std::forward<inner_type>(range))}
gap_decorator(other_range_t && range) : ungapped_view{views::type_reduce(std::forward<inner_type>(range))}
{} // TODO (@smehringer) only works for copyable views. Has to be changed once views are not required to be copyable anymore.
// !\}

Expand Down Expand Up @@ -557,7 +557,7 @@ class gap_decorator
}

//!\brief Stores a (copy of a) view to the ungapped, underlying sequence.
decltype(views::all(std::declval<inner_type &&>())) ungapped_view{};
decltype(views::type_reduce(std::declval<inner_type &&>())) ungapped_view{};

//!\brief Set storing the anchor gaps.
anchor_set_type anchors{};
Expand Down
90 changes: 90 additions & 0 deletions include/seqan3/range/views/as_const.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// -----------------------------------------------------------------------------------------------------
// Copyright (c) 2006-2019, Knut Reinert & Freie Universität Berlin
// Copyright (c) 2016-2019, 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 <hannes.hauswedell AT fu-berlin.de>
* \brief Provides seqan3::views::as_const.
*/

#pragma once

#include <seqan3/core/type_traits/function.hpp>
#include <seqan3/std/ranges>

namespace seqan3::detail
{

//!\brief Function object for seqan3::views::as_const.
struct as_const_fn
{
//!\brief Operator that returns rvalues as rvalues.
template <typename t>
t operator()(t const && arg) const
{
return std::move(arg);
}

//!\brief Operator that returns lvalue references as lvalue-to-const-references.
template <typename t>
t const & operator()(t const & arg) const
{
return arg;
}
};

} // namespace seqan3::detail

namespace seqan3::views
{

/*!\name General purpose views
* \{
*/

/*!\brief A view that provides only `const &` to elements of the underlying range.
* \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]
* \returns A range of `const`-protected elements.
* \ingroup views
*
* \details
*
* \header_file{seqan3/range/views/as_const.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 | | *preserved* |
* | std::ranges::common_range | | *preserved* |
* | std::ranges::output_range | | *lost* |
* | seqan3::const_iterable_range | | *preserved* |
* | std::semiregular | | *preserved* |
* | | | |
* | std::ranges::range_reference_t | | `t &` -> `t const &` but `t` -> `t` |
*
* See the \link views views submodule documentation \endlink for detailed descriptions of the view properties.
*
* ### Example
*
* \include test/snippet/range/views/as_const.cpp
* \hideinitializer
*/
inline auto const as_const = std::views::transform(seqan3::detail::as_const_fn{});
//!\}

} // namespace seqan3::views
Loading