Commit d0e4b792 authored by Jan Koniarik's avatar Jan Koniarik
Browse files

view now uses concepts instead of enable_if_t

parent 2b6e8c66
Pipeline #93974 passed with stage
in 40 seconds
...@@ -26,15 +26,14 @@ class view { ...@@ -26,15 +26,14 @@ class view {
constexpr view() = default; constexpr view() = default;
/// constructor from Container, uses begin/end of the container /// constructor from Container, uses begin/end of the container
template <typename Container> constexpr view(range_container auto &cont)
constexpr view(Container &cont) : begin_(std::begin(cont)), end_(std::end(cont)) {} : begin_(std::begin(cont)), end_(std::end(cont)) {}
/// constructor from the iterators that should internally be stored /// constructor from the iterators that should internally be stored
constexpr view(Iterator begin, Iterator end) constexpr view(Iterator begin, Iterator end)
: begin_(std::move(begin)), end_(std::move(end)) {} : begin_(std::move(begin)), end_(std::move(end)) {}
template <typename OtherIterator, template <std::convertible_to<Iterator> OtherIterator>
std::enable_if_t<std::is_convertible_v<OtherIterator, Iterator>> * = nullptr>
constexpr view(view<OtherIterator> other) : begin_(other.begin()), end_(other.end()) {} constexpr view(view<OtherIterator> other) : begin_(other.begin()), end_(other.end()) {}
/// Start of the dataset iterator /// Start of the dataset iterator
...@@ -71,7 +70,7 @@ class view { ...@@ -71,7 +70,7 @@ class view {
}; };
/// The container deduction guide uses iterator_of_t /// The container deduction guide uses iterator_of_t
template <typename Container> template <range_container Container>
view(Container &cont) -> view<iterator_of_t<Container>>; view(Container &cont) -> view<iterator_of_t<Container>>;
/// Support for our deduction guide to types - is_view_v /// Support for our deduction guide to types - is_view_v
...@@ -89,16 +88,15 @@ constexpr view<Iter> view_n(Iter begin, Count n) { ...@@ -89,16 +88,15 @@ constexpr view<Iter> view_n(Iter begin, Count n) {
/// Creates the view over over Container, where we ignore first r*size/2 items /// Creates the view over over Container, where we ignore first r*size/2 items
/// and last r*size/2 items. This can be used to get the dataset without /// and last r*size/2 items. This can be used to get the dataset without
/// first/last 5% for example, by using r=0.1 /// first/last 5% for example, by using r=0.1
template <typename Container> template <range_container Container>
constexpr view<iterator_of_t<Container>> trim_view(Container &cont, float r) { constexpr view<iterator_of_t<Container>> trim_view(Container &cont, float r) {
std::size_t step = cont.size() * (1.f - r) / 2.f; std::size_t step = cont.size() * (1.f - r) / 2.f;
return {cont.begin() + step, cont.end() - step}; return {cont.begin() + step, cont.end() - step};
} }
/// Returns view to the Container in reverse order. /// Returns view to the Container in reverse order.
template <typename Container, constexpr auto reversed(referenceable_container auto &&container)
typename = std::enable_if_t<std::is_reference_v<Container> || is_view_v<Container>>> -> view<decltype(container.rbegin())> {
constexpr auto reversed(Container &&container) -> view<decltype(container.rbegin())> {
return {container.rbegin(), container.rend()}; return {container.rbegin(), container.rend()};
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment