BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
convert.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2022 deCODE Genetics
3// Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
4// Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
5// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
6// shipped with this file and also available at: https://github.com/biocpp/biocpp-core/blob/main/LICENSE.md
7// -----------------------------------------------------------------------------------------------------
8
14#pragma once
15
16#include <concepts>
17#include <ranges>
18
19#include <bio/core.hpp>
20
21namespace bio::ranges::views
22{
23
72template <typename out_t>
73auto const convert = std::views::transform(
74 [](auto && in) -> out_t
75 {
76 static_assert(std::convertible_to<decltype(in) &&, out_t> || std::constructible_from<out_t, decltype(in) &&>,
77 "The reference type of the input to views::convert is not convertible to out_t.");
78
79 if constexpr (std::convertible_to<decltype(in) &&, out_t>)
80 return std::forward<decltype(in)>(in);
81 else
82 return static_cast<out_t>(std::forward<decltype(in)>(in));
83 });
84
86
87} // namespace bio::ranges::views
Provides platform and dependency checks.
auto const convert
A view that converts each element in the input range (implicitly or via static_cast).
Definition: convert.hpp:73
The BioC++ namespace for views.