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_TYPES_POINTERS_H
24#define VCL_TYPES_POINTERS_H
25
26#include <type_traits>
27#include <utility>
28
29namespace vcl {
30
41template<typename T>
42using RemovePtr = std::remove_pointer_t<T>;
43
54template<typename T>
55using RemoveRef = std::remove_reference_t<T>;
56
65template<typename T>
66using RemoveCVRefAndPointer = std::remove_cvref_t<RemovePtr<T>>;
67
77template<typename T>
78using RemoveConstFromPointer = std::conditional_t<
79 std::is_pointer_v<T>,
80 std::add_pointer_t<std::remove_cv_t<RemovePtr<T>>>,
81 T>;
82
94template<typename T>
96{
97 if constexpr (std::is_pointer_v<RemoveRef<T>>) {
98 return *obj;
99 }
100 else {
101 return std::forward<T>(obj);
102 }
103}
104
115template<typename T>
117{
118 if constexpr (std::is_pointer_v<RemoveRef<T>>) {
119 return obj;
120 }
121 else {
122 return &obj;
123 }
124}
125
126} // namespace vcl
127
128#endif // VCL_TYPES_POINTERS_H
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
std::remove_pointer_t< T > RemovePtr
Utility alias to get a type without the pointer. e.g. If T is int*, the resulting type is int.
Definition pointers.h:42
std::remove_reference_t< T > RemoveRef
Utility alias to get a type type without the reference. e.g. If T is int&, the resulting type is int.
Definition pointers.h:55
auto & dereferencePtr(T &&obj)
Utility function that applies the unary operator '*' to the argument only if the object is a pointer,...
Definition pointers.h:95
std::remove_cvref_t< RemovePtr< T > > RemoveCVRefAndPointer
Utility alias to get clean type from an input type that could have a reference or a pointer.
Definition pointers.h:66
std::conditional_t< std::is_pointer_v< T >, std::add_pointer_t< std::remove_cv_t< RemovePtr< T > > >, T > RemoveConstFromPointer
Utility alias to get a pointer type without the constness. e.g. If T is const int*,...
Definition pointers.h:81
auto addressOfObj(T &obj)
Utility function that applies the unary operator '&' to the argument only if it is not a pointer.
Definition pointers.h:116