Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-07-16 08:07:43

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 #include <concepts>
0012 #include <type_traits>
0013 
0014 namespace Acts {
0015 
0016 /// @brief The Pointer concept is an extension of the usual std::is_pointer_v type trait to
0017 ///         also include the smart pointers like
0018 ///     std::shared_ptr<T>,
0019 ///     std::unique_ptr<T>
0020 ///  The smart pointer is required to have an element_type typedef indicating
0021 /// over which data type the pointer is constructed, the arrow operator
0022 ///
0023 ///      T* operator->() const;
0024 ///  and also the dereference operator
0025 ///
0026 ///      T& operator*() const
0027 template <typename Pointer_t>
0028 concept SmartPointerConcept = requires(Pointer_t ptr) {
0029   typename Pointer_t::element_type;
0030   /// @brief arrow operator element_type* operator->() const;
0031   {
0032     ptr.operator->()
0033   } -> std::same_as<std::add_pointer_t<typename Pointer_t::element_type>>;
0034   /// @brief dereference operator element_type& operator*() const;
0035   { ptr.operator*() } -> std::same_as<typename Pointer_t::element_type&>;
0036   /// @brief Simple cast to check for if(ptr)
0037   { ptr.operator bool() };
0038 };
0039 template <typename Pointer_t>
0040 concept PointerConcept =
0041     (std::is_pointer_v<Pointer_t> || SmartPointerConcept<Pointer_t>);
0042 /// @brief Introduce the Acts version of the pointer remove type trait because we want to
0043 ///        fetch the underlying type for the pointer concept and std::library
0044 ///        does not allow for an extension of the std::remove_pointer;
0045 template <typename T>
0046 struct RemovePointer {
0047   /// Type alias for the original type (non-pointer case)
0048   using type = T;
0049 };
0050 
0051 /// @brief  This specialization allows std::remove_pointer to work with types satisfying
0052 ///         Acts::SmartPointerConcept, similar to how it works with raw pointers
0053 template <SmartPointerConcept T>
0054 struct RemovePointer<T> {
0055   /// Type alias for the element type pointed to by smart pointer
0056   using type = typename T::element_type;
0057 };
0058 /// @brief ordinary specialization for pointers
0059 template <PointerConcept T>
0060 struct RemovePointer<T> {
0061   /// Type alias for the type pointed to by raw pointer
0062   using type = std::remove_pointer_t<T>;
0063 };
0064 /// Helper type alias for removing pointer from type
0065 template <typename T>
0066 using RemovePointer_t = RemovePointer<T>::type;
0067 
0068 /// @brief Construct a const pointer dereference
0069 template <PointerConcept T>
0070 using ConstDeRef_t = std::add_const_t<RemovePointer_t<T>>&;
0071 
0072 }  // namespace Acts