|
|
|||
File indexing completed on 2025-12-14 09:39:51
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 /// Type alias for the original type (non-pointer case) 0044 using type = T; 0045 }; 0046 0047 /// @brief This specialization allows std::remove_pointer to work with types satisfying 0048 /// Acts::SmartPointerConcept, similar to how it works with raw pointers 0049 template <SmartPointerConcept T> 0050 struct RemovePointer<T> { 0051 /// Type alias for the element type pointed to by smart pointer 0052 using type = typename T::element_type; 0053 }; 0054 /// @brief ordinary specialization for pointers 0055 template <PointerConcept T> 0056 struct RemovePointer<T> { 0057 /// Type alias for the type pointed to by raw pointer 0058 using type = std::remove_pointer_t<T>; 0059 }; 0060 /// Helper type alias for removing pointer from type 0061 template <typename T> 0062 using RemovePointer_t = RemovePointer<T>::type; 0063 0064 } // namespace Acts
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|