Loading...
Searching...
No Matches
type_reduce.hpp
Go to the documentation of this file.
// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: BSD-3-Clause
#pragma once
#include <concepts>
#include <ranges>
#include <span>
#include <string_view>
#include <seqan3/core/detail/template_inspection.hpp>
#include <seqan3/core/range/detail/adaptor_base.hpp>
namespace seqan3::detail
{
// ============================================================================
// type_reduce_fn (adaptor definition)
// ============================================================================
class type_reduce_fn : public adaptor_base<type_reduce_fn>
{
private:
using base_t = adaptor_base<type_reduce_fn>;
public:
using base_t::base_t;
private:
friend base_t;
template <std::ranges::range urng_t>
static constexpr auto impl(urng_t && urange)
{
static_assert(
std::ranges::viewable_range<urng_t>,
"The views::type_reduce adaptor can only be passed viewable_ranges, i.e. Views or &-to-non-View.");
// string_view
if constexpr (is_type_specialisation_of_v<std::remove_cvref_t<urng_t>, std::basic_string_view>)
{
return std::views::all(std::forward<urng_t>(urange));
}
// string const &
else if constexpr (is_type_specialisation_of_v<std::remove_cvref_t<urng_t>, std::basic_string>
&& std::is_const_v<std::remove_reference_t<urng_t>>)
{
return std::basic_string_view{std::ranges::data(urange), std::ranges::size(urange)};
}
// contiguous
else if constexpr (std::ranges::borrowed_range<urng_t> && std::ranges::contiguous_range<urng_t>
&& std::ranges::sized_range<urng_t>)
{
return std::span{std::ranges::data(urange), std::ranges::size(urange)};
}
// random_access
else if constexpr (std::ranges::borrowed_range<urng_t> && std::ranges::random_access_range<urng_t>
&& std::ranges::sized_range<urng_t>)
{
return std::ranges::subrange<std::ranges::iterator_t<urng_t>, std::ranges::iterator_t<urng_t>>{
std::ranges::begin(urange),
std::ranges::begin(urange) + std::ranges::size(urange),
std::ranges::size(urange)};
}
// pass to std::views::all (will return a view or ref-view)
else
{
return std::views::all(std::forward<urng_t>(urange));
}
}
};
} // namespace seqan3::detail
// ============================================================================
// views::type_reduce (adaptor instance definition)
// ============================================================================
namespace seqan3::views
{
inline constexpr auto type_reduce = detail::type_reduce_fn{};
} // namespace seqan3::views
namespace seqan3
{
template <typename t>
using type_reduce_t = decltype(views::type_reduce(std::declval<t>()));
} // namespace seqan3
adaptor_base.hpp
Provides seqan3::detail::adaptor_base and seqan3::detail::combined_adaptor.
std::declval
T declval(T... args)
std::forward
T forward(T... args)
seqan3::views::type_reduce
constexpr auto type_reduce
A view adaptor that behaves like std::views::all, but type erases certain ranges.
Definition type_reduce.hpp:147
std::is_const_v
T is_const_v
seqan3::views
The SeqAn namespace for views.
Definition char_strictly_to.hpp:19
seqan3
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
seqan3::type_reduce_t
decltype(views::type_reduce(std::declval< t >())) type_reduce_t
Deduces the return value of seqan3::views::type_reduce.
Definition type_reduce.hpp:159
string_view
template_inspection.hpp
Provides type traits for working with templates.
Hide me