Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:05

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 // Project include(s)
0012 #include "detray/definitions/detail/qualifiers.hpp"
0013 #include "detray/utils/ranges/ranges.hpp"
0014 
0015 namespace detray::ranges {
0016 
0017 /// @brief Struct that implements a pointer based view on a single element.
0018 ///
0019 /// @tparam value_t type of the single element (outside of a container)
0020 ///
0021 /// @note Does not take ownership of the value it operates on. Its lifetime
0022 /// needs to be guaranteed throughout iteration or between iterations with the
0023 /// same view instance.
0024 /// @note Is not fit for lazy evaluation.
0025 template <typename value_t>
0026 class pointer_view
0027     : public detray::ranges::view_interface<pointer_view<value_t>> {
0028  public:
0029   using iterator_t = value_t*;
0030 
0031   /// Default constructor
0032   pointer_view() = default;
0033 
0034   /// Construct iterator from the single @param value - copy
0035   DETRAY_HOST_DEVICE constexpr explicit pointer_view(value_t& value)
0036       : m_value{&value} {}
0037 
0038   /// @return the pointer value
0039   DETRAY_HOST_DEVICE
0040   constexpr auto operator*() const -> const value_t& { return *m_value; }
0041 
0042   /// @return the pointer value
0043   DETRAY_HOST_DEVICE
0044   constexpr auto operator*() -> value_t& { return *m_value; }
0045 
0046   /// @returns value pointer.
0047   DETRAY_HOST_DEVICE
0048   constexpr auto begin() noexcept -> value_t* { return m_value; }
0049 
0050   /// @returns value pointer - const
0051   DETRAY_HOST_DEVICE
0052   constexpr auto begin() const noexcept -> const value_t* { return m_value; }
0053 
0054   /// @returns sentinel position.
0055   DETRAY_HOST_DEVICE
0056   constexpr auto end() noexcept -> value_t* { return m_value + 1; }
0057 
0058   /// @returns sentinel position - const
0059   DETRAY_HOST_DEVICE
0060   constexpr auto end() const noexcept -> const value_t* { return m_value + 1; }
0061 
0062   /// @returns a pointer to the beginning of the data
0063   DETRAY_HOST_DEVICE
0064   constexpr auto data() noexcept -> value_t* { return m_value; }
0065 
0066   /// @returns a pointer to the beginning of the data - const
0067   DETRAY_HOST_DEVICE
0068   constexpr auto data() const noexcept -> const value_t* { return m_value; }
0069 
0070   /// @returns the size of the pointer view, which is always 'one'.
0071   DETRAY_HOST_DEVICE
0072   static constexpr auto size() noexcept -> std::size_t { return 1; }
0073 
0074   /// @returns the value directly
0075   DETRAY_HOST_DEVICE
0076   constexpr auto front() noexcept -> value_t { return *m_value; }
0077 
0078   /// @returns the value directly
0079   DETRAY_HOST_DEVICE
0080   constexpr auto back() noexcept -> value_t { return *m_value; }
0081 
0082   /// @returns the value directly
0083   DETRAY_HOST_DEVICE constexpr auto operator[](const dindex /*unused*/) const
0084       -> value_t {
0085     return *m_value;
0086   }
0087 
0088  private:
0089   value_t* m_value{};
0090 };
0091 
0092 namespace views {
0093 
0094 /// @brief interface type to construct a @c pointer_view with CTAD
0095 template <typename value_t>
0096 struct pointer : public detray::ranges::pointer_view<const value_t> {
0097   using base_type = detray::ranges::pointer_view<const value_t>;
0098 
0099   constexpr pointer() = default;
0100 
0101   template <typename deduced_value_t>
0102   DETRAY_HOST_DEVICE constexpr explicit pointer(deduced_value_t& value)
0103       : base_type(value) {}
0104 };
0105 
0106 // deduction guides
0107 
0108 template <typename deduced_value_t>
0109 DETRAY_HOST_DEVICE pointer(deduced_value_t&) -> pointer<deduced_value_t>;
0110 
0111 }  // namespace views
0112 
0113 }  // namespace detray::ranges