SeqAn3 3.3.0-rc.1
The Modern C++ library for sequence analysis.
 
Loading...
Searching...
No Matches
to.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2022, Knut Reinert & MPI für molekulare Genetik
4// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5// shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6// -----------------------------------------------------------------------------------------------------
7
13#pragma once
14
15#include <algorithm>
16#include <ranges>
17
20
21namespace seqan3::detail
22{
23
25template <typename container_t>
26 requires (!std::ranges::view<container_t>)
27struct to_fn
28{
29private:
34 template <std::ranges::input_range rng_t>
35 requires std::convertible_to<std::ranges::range_reference_t<rng_t>, std::ranges::range_value_t<container_t>>
36 auto impl(rng_t && rng, container_t & container) const
37 {
39 }
40
42 template <std::ranges::input_range rng_t>
43 auto impl(rng_t && rng, container_t & container) const
44 requires std::ranges::input_range<std::ranges::range_value_t<rng_t>>
45 {
47 auto inner_rng = rng | std::views::transform(adaptor);
49 }
50
51public:
58 template <std::ranges::input_range rng_t, typename... args_t>
59 constexpr auto operator()(rng_t && rng, args_t &&... args) const
60 {
61 auto new_container = container_t(std::forward<args_t>(args)...);
62
63 // reserve memory if functionality is available
64 if constexpr (std::ranges::sized_range<rng_t> && requires (container_t c) { c.reserve(size_t{}); })
65 new_container.reserve(std::ranges::size(rng));
66
67 impl(std::forward<rng_t>(rng), new_container);
68 return new_container;
69 }
70};
71
75template <template <typename> typename container_t>
77{
84 template <std::ranges::input_range rng_t, typename... args_t>
85 constexpr auto operator()(rng_t && rng, args_t &&... args) const
86 {
88 return adaptor(std::forward<rng_t>(rng), std::forward<args_t>(args)...);
89 }
90};
91
92} // namespace seqan3::detail
93
94namespace seqan3::ranges
95{
96
113template <typename container_t, typename... args_t>
114constexpr auto to(args_t &&... args)
115{
116 return detail::adaptor_from_functor{detail::to_fn<container_t>{}, std::forward<args_t>(args)...};
117}
118
123template <template <typename...> typename container_t, typename... args_t>
124constexpr auto to(args_t &&... args)
125{
126 return detail::adaptor_from_functor{detail::to_template_template_fn<container_t>{}, std::forward<args_t>(args)...};
127}
128
133template <typename container_t, std::ranges::input_range rng_t, typename... args_t>
134constexpr auto to(rng_t && rng, args_t &&... args)
135{
137 std::forward<args_t>(args)...}(std::forward<rng_t>(rng));
138}
139
144template <template <class...> typename container_t, std::ranges::input_range rng_t, typename... args_t>
145constexpr auto to(rng_t && rng, args_t &&... args)
146{
148 std::forward<args_t>(args)...}(std::forward<rng_t>(rng));
149}
150
151} // namespace seqan3::ranges
Provides seqan3::detail::adaptor_from_functor.
T back_inserter(T... args)
Template for range adaptor closure objects that store arguments and wrap a proto-adaptor.
Definition: adaptor_from_functor.hpp:57
T copy(T... args)
constexpr auto to(args_t &&... args)
Converts a range to a container.
Definition: to.hpp:114
The (most general) container concept as defined by the standard library.
The internal SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
Function object to convert a std::ranges::input_range to a fully defined container.
Definition: to.hpp:28
auto impl(rng_t &&rng, container_t &container) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: to.hpp:43
constexpr auto operator()(rng_t &&rng, args_t &&... args) const
Converts a template-template into a container.
Definition: to.hpp:59
auto impl(rng_t &&rng, container_t &container) const
Copies a range into a container.
Definition: to.hpp:36
Similar to to_fn, but accepts a template-template as argument, e.g.: to_fn<vector> instead of to_fn<v...
Definition: to.hpp:77
constexpr auto operator()(rng_t &&rng, args_t &&... args) const
Converts a template-template into a container.
Definition: to.hpp:85
Provides concepts that do not have equivalents in C++20.