Quetzal-CoaTL
The Coalescence Template Library
Loading...
Searching...
No Matches
ranges_to.hpp
1// Copyright 2021 Arnaud Becheler <abechele@umich.edu>
2
10
11#pragma once
12
13#include <ranges>
14
15namespace quetzal::utils
16{
17namespace details
18{
19 // Type acts as a tag to find the correct operator| overload
20 template <typename C>
21 struct to_helper {
22 };
23
24 // This actually does the work
25 template <typename Container, std::ranges::range R>
26 requires std::convertible_to<std::ranges::range_value_t<R>, typename Container::value_type>
27 Container operator|(R&& r, to_helper<Container>)
28 {
29 return Container{r.begin(), r.end()};
30 }
31}
32
33// Couldn't find an concept for container, however a
34// container is a range, but not a view.
35template <std::ranges::range Container>
36requires (!std::ranges::view<Container>)
37auto to() {
38 return details::to_helper<Container>{};
39}
40}
Miscellaneous details.
Definition utils.hpp:21
Definition ranges_to.hpp:21