Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 07:48:18

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