ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
pointer.hpp
1// This file is part of the ACTS project.
2//
3// Copyright (C) 2016 CERN for the benefit of the ACTS project
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9#pragma once
10
11// Project include(s)
12#include "detray/definitions/detail/qualifiers.hpp"
13#include "detray/utils/ranges/ranges.hpp"
14
15namespace detray::ranges {
16
25template <typename value_t>
27 : public detray::ranges::view_interface<pointer_view<value_t>> {
28 public:
30 using iterator_t = value_t*;
31
33 pointer_view() = default;
34
36 DETRAY_HOST_DEVICE constexpr explicit pointer_view(value_t& value)
37 : m_value{&value} {}
38
40 DETRAY_HOST_DEVICE
41 constexpr auto operator*() const -> const value_t& { return *m_value; }
42
44 DETRAY_HOST_DEVICE
45 constexpr auto operator*() -> value_t& { return *m_value; }
46
48 DETRAY_HOST_DEVICE
49 constexpr auto begin() noexcept -> value_t* { return m_value; }
50
52 DETRAY_HOST_DEVICE
53 constexpr auto begin() const noexcept -> const value_t* { return m_value; }
54
56 DETRAY_HOST_DEVICE
57 constexpr auto end() noexcept -> value_t* { return m_value + 1; }
58
60 DETRAY_HOST_DEVICE
61 constexpr auto end() const noexcept -> const value_t* { return m_value + 1; }
62
64 DETRAY_HOST_DEVICE
65 constexpr auto data() noexcept -> value_t* { return m_value; }
66
68 DETRAY_HOST_DEVICE
69 constexpr auto data() const noexcept -> const value_t* { return m_value; }
70
72 DETRAY_HOST_DEVICE
73 static constexpr auto size() noexcept -> std::size_t { return 1; }
74
76 DETRAY_HOST_DEVICE
77 constexpr auto front() noexcept -> value_t { return *m_value; }
78
80 DETRAY_HOST_DEVICE
81 constexpr auto back() noexcept -> value_t { return *m_value; }
82
84 DETRAY_HOST_DEVICE constexpr auto operator[](const dindex /*unused*/) const
85 -> value_t {
86 return *m_value;
87 }
88
89 private:
90 value_t* m_value{};
91};
92
93namespace views {
94
96template <typename value_t>
97struct pointer : public detray::ranges::pointer_view<const value_t> {
100
101 constexpr pointer() = default;
102
105 template <typename deduced_value_t>
106 DETRAY_HOST_DEVICE constexpr explicit pointer(deduced_value_t& value)
107 : base_type(value) {}
108};
109
110// deduction guides
111
112template <typename deduced_value_t>
113DETRAY_HOST_DEVICE_DEDUCTION_GUIDE pointer(deduced_value_t&)
114 -> pointer<deduced_value_t>;
115
116} // namespace views
117
118} // namespace detray::ranges
Struct that implements a pointer based view on a single element.
Definition pointer.hpp:27
constexpr pointer_view(value_t &value)
Construct iterator from the single.
Definition pointer.hpp:36
pointer_view()=default
Default constructor.
constexpr auto operator*() const -> const value_t &
Definition pointer.hpp:41
constexpr auto front() noexcept -> value_t
Definition pointer.hpp:77
constexpr auto operator*() -> value_t &
Definition pointer.hpp:45
constexpr auto end() const noexcept -> const value_t *
Definition pointer.hpp:61
constexpr auto data() noexcept -> value_t *
Definition pointer.hpp:65
constexpr auto operator[](const dindex) const -> value_t
Definition pointer.hpp:84
static constexpr auto size() noexcept -> std::size_t
Definition pointer.hpp:73
constexpr auto begin() noexcept -> value_t *
Definition pointer.hpp:49
constexpr auto data() const noexcept -> const value_t *
Definition pointer.hpp:69
value_t * iterator_t
Pointer iterator over the referenced element.
Definition pointer.hpp:30
constexpr auto back() noexcept -> value_t
Definition pointer.hpp:81
constexpr auto begin() const noexcept -> const value_t *
Definition pointer.hpp:53
constexpr auto end() noexcept -> value_t *
Definition pointer.hpp:57
Defines a detray 'view'.
Definition ranges.hpp:190
unsigned int dindex
Default index type.
Definition indexing.hpp:18
detray::ranges::pointer_view< const value_t > base_type
Base implementation referencing one constant value.
Definition pointer.hpp:99
constexpr pointer(deduced_value_t &value)
Construct a view referring to value.
Definition pointer.hpp:106