ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
single.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
27template <typename value_t>
29 : public detray::ranges::view_interface<single_view<value_t>> {
30 public:
32 using iterator_t = value_t*;
33
35 constexpr single_view() = default;
36
40 DETRAY_HOST_DEVICE constexpr explicit single_view(const value_t& value)
41 : m_value{value} {}
42
46 DETRAY_HOST_DEVICE constexpr explicit single_view(value_t&& value)
47 : m_value{std::move(value)} {}
48
52 template <class... Args>
53 DETRAY_HOST_DEVICE constexpr explicit single_view(std::in_place_t /*tag*/,
54 Args&&... args)
55 : m_value{std::in_place, std::forward<Args>(args)...} {}
56
59 DETRAY_HOST_DEVICE
60 constexpr auto value() const -> value_t { return m_value; }
61
64 DETRAY_HOST_DEVICE
65 constexpr auto ref() const -> const value_t& { return m_value; }
68 DETRAY_HOST_DEVICE
69 constexpr auto ref() -> value_t& { return m_value; }
70
72 DETRAY_HOST_DEVICE
73 constexpr auto begin() noexcept -> value_t* { return &m_value; }
74
76 DETRAY_HOST_DEVICE
77 constexpr auto begin() const noexcept -> const value_t* { return &m_value; }
78
80 DETRAY_HOST_DEVICE
81 constexpr auto end() noexcept -> value_t* { return &m_value + 1; }
82
84 DETRAY_HOST_DEVICE
85 constexpr auto end() const noexcept -> const value_t* { return &m_value + 1; }
86
88 DETRAY_HOST_DEVICE
89 constexpr auto data() noexcept -> value_t* { return &m_value; }
90
92 DETRAY_HOST_DEVICE
93 constexpr auto data() const noexcept -> const value_t* { return &m_value; }
94
96 DETRAY_HOST_DEVICE
97 static constexpr auto size() noexcept -> std::size_t { return 1; }
98
100 DETRAY_HOST_DEVICE
101 constexpr auto front() noexcept -> value_t { return m_value; }
102
104 DETRAY_HOST_DEVICE
105 constexpr auto back() noexcept -> value_t { return m_value; }
106
108 DETRAY_HOST_DEVICE constexpr auto operator[](const dindex /*unused*/) const
109 -> value_t {
110 return m_value;
111 }
112
113 private:
114 value_t m_value{};
115};
116
117namespace views {
118
120template <typename value_t>
121struct single : public detray::ranges::single_view<value_t> {
124
125 constexpr single() = default;
126
129 template <typename deduced_value_t>
130 requires(!std::same_as<deduced_value_t, single>)
131 DETRAY_HOST_DEVICE constexpr explicit single(const deduced_value_t& value)
132 : base_type(value) {}
133
136 template <typename deduced_value_t>
137 requires(!std::same_as<deduced_value_t, single>)
138 DETRAY_HOST_DEVICE constexpr explicit single(deduced_value_t&& value)
139 : base_type(std::forward<deduced_value_t>(value)) {}
140
144 template <class... Args>
145 DETRAY_HOST_DEVICE constexpr explicit single(std::in_place_t /*unused*/,
146 Args&&... args)
147 : base_type(std::in_place /*tag*/, std::forward<Args>(args)... /*args*/) {
148 }
149};
150
151// deduction guides
152
153template <typename deduced_value_t>
154DETRAY_HOST_DEVICE_DEDUCTION_GUIDE single(deduced_value_t)
155 -> single<deduced_value_t>;
156
157} // namespace views
158
159} // namespace detray::ranges
Struct that implements a view on a single element.
Definition single.hpp:29
constexpr auto end() const noexcept -> const value_t *
Definition single.hpp:85
constexpr auto data() noexcept -> value_t *
Definition single.hpp:89
constexpr single_view(value_t &&value)
Construct the view by moving in its single element.
Definition single.hpp:46
constexpr auto ref() -> value_t &
Return a mutable reference to the stored element.
Definition single.hpp:69
constexpr auto operator[](const dindex) const -> value_t
Definition single.hpp:108
constexpr auto back() noexcept -> value_t
Definition single.hpp:105
constexpr single_view(const value_t &value)
Construct the view by copying its single element.
Definition single.hpp:40
constexpr auto begin() noexcept -> value_t *
Definition single.hpp:73
constexpr single_view()=default
Default constructor.
static constexpr auto size() noexcept -> std::size_t
Definition single.hpp:97
entry_t * iterator_t
Definition single.hpp:32
constexpr auto end() noexcept -> value_t *
Definition single.hpp:81
constexpr auto begin() const noexcept -> const value_t *
Definition single.hpp:77
constexpr single_view(std::in_place_t, Args &&... args)
Construct value in place from args.
Definition single.hpp:53
constexpr auto value() const -> entry_t
Definition single.hpp:60
constexpr auto data() const noexcept -> const value_t *
Definition single.hpp:93
constexpr auto ref() const -> const value_t &
Return a const reference to the stored element.
Definition single.hpp:65
constexpr auto front() noexcept -> value_t
Definition single.hpp:101
Defines a detray 'view'.
Definition ranges.hpp:190
unsigned int dindex
Default index type.
Definition indexing.hpp:18
constexpr single(const deduced_value_t &value)
Construct the view by copying a value.
Definition single.hpp:131
constexpr single(std::in_place_t, Args &&... args)
Construct the stored value in place.
Definition single.hpp:145
constexpr single(deduced_value_t &&value)
Construct the view by moving a value.
Definition single.hpp:138
detray::ranges::single_view< value_t > base_type
Base implementation storing the single value.
Definition single.hpp:123