SeqAn3  3.2.0-rc.1
The Modern C++ library for sequence analysis.
utility/views/convert.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 <concepts>
16 #include <ranges>
17 
19 
20 namespace seqan3::views
21 {
68 template <typename out_t>
69 inline constexpr auto convert = std::views::transform(
70  [](auto && in) -> out_t
71  {
72  static_assert(std::convertible_to<decltype(in) &&, out_t> || explicitly_convertible_to<decltype(in) &&, out_t>,
73  "The reference type of the input to views::convert is not convertible to out_t.");
74 
75  if constexpr (std::convertible_to<decltype(in) &&, out_t>)
76  return std::forward<decltype(in)>(in);
77  else
78  return static_cast<out_t>(std::forward<decltype(in)>(in));
79  });
80 
81 } // namespace seqan3::views
The <concepts> header from C++20's standard library.
decltype(detail::transform< trait_t >(list_t{})) transform
Apply a transformation trait to every type in the list and return a seqan3::type_list of the results.
Definition: type_list/traits.hpp:469
constexpr auto convert
A view that converts each element in the input range (implicitly or via static_cast).
Definition: utility/views/convert.hpp:69
Checks whether from can be explicitly converted to to.
The SeqAn namespace for views.
Definition: char_strictly_to.hpp:22
The <ranges> header from C++20's standard library.
Provides concepts that do not have equivalents in C++20.