Visual Computing Library
Loading...
Searching...
No Matches
pointers.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_VIEWS_POINTERS_H
24#define VCL_VIEWS_POINTERS_H
25
26#include <ranges>
27
28namespace vcl::views {
29
30namespace detail {
31
32struct NotNullView
33{
34 constexpr NotNullView() = default;
35
36 template<std::ranges::range R>
37 friend constexpr auto operator|(R&& r, NotNullView)
38 {
39 return std::views::filter(r, [](auto* p) {
40 return p != nullptr;
41 });
42 }
43};
44
45struct DereferenceView
46{
47 constexpr DereferenceView() = default;
48
49 template<std::ranges::range R>
50 friend constexpr auto operator|(R&& r, DereferenceView)
51 {
52 return std::views::transform(r, [](auto p) {
53 return *p;
54 });
55 }
56};
57
58struct AddressOfView
59{
60 constexpr AddressOfView() = default;
61
62 template<std::ranges::range R>
63 friend constexpr auto operator|(R&& r, AddressOfView)
64 {
65 return std::views::transform(r, [](auto& o) {
66 return &o;
67 });
68 }
69};
70
71struct ConstAddressOfView
72{
73 constexpr ConstAddressOfView() = default;
74
75 template<std::ranges::range R>
76 friend constexpr auto operator|(R&& r, ConstAddressOfView)
77 {
78 return std::views::transform(r, [](const auto& o) {
79 return &o;
80 });
81 }
82};
83
84} // namespace detail
85
92inline constexpr detail::NotNullView notNull;
93
110inline constexpr detail::DereferenceView deref;
111
120inline constexpr detail::AddressOfView addrOf;
121
132inline constexpr detail::ConstAddressOfView constAddrOf;
133
134} // namespace vcl::views
135
136#endif // VCL_VIEWS_POINTERS_H
constexpr detail::ConstAddressOfView constAddrOf
The constAddrOf view applies the address-of operator & on the input view.
Definition pointers.h:132
constexpr detail::NotNullView notNull
The notNull view allows to filter the pointers of a range. The resulting view will iterate only on th...
Definition pointers.h:92
constexpr detail::DereferenceView deref
The deref view the dereference operator * on the input view.
Definition pointers.h:110
constexpr detail::AddressOfView addrOf
The addrOf view applies the address-of operator & on the input view.
Definition pointers.h:120