Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:11

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 <utility>
0012 
0013 namespace Acts::detail {
0014 
0015 /// Internal holder type for referencing a backend without ownership
0016 template <typename T>
0017 struct RefHolder {
0018   T* ptr;
0019 
0020   explicit RefHolder(T* _ptr) : ptr{_ptr} {}
0021   explicit RefHolder(T& ref) : ptr{&ref} {}
0022 
0023   const T& operator*() const { return *ptr; }
0024   T& operator*() { return *ptr; }
0025 
0026   const T* operator->() const { return ptr; }
0027   T* operator->() { return ptr; }
0028 };
0029 
0030 /// Internal holder type for referencing a backend without ownership that is
0031 /// const
0032 template <typename T>
0033 struct ConstRefHolder {
0034   const T* ptr;
0035 
0036   explicit ConstRefHolder(const T* _ptr) : ptr{_ptr} {}
0037   explicit ConstRefHolder(const T& ref) : ptr{&ref} {}
0038 
0039   const T& operator*() const { return *ptr; }
0040 
0041   const T* operator->() const { return ptr; }
0042 };
0043 
0044 /// Internal holder type holding a backend container by value
0045 template <typename T>
0046 struct ValueHolder {
0047   T val;
0048 
0049   // Let's be clear with the user that we take the ownership
0050   // Only require rvalues and avoid hidden copies
0051   ValueHolder(T& _val) = delete;
0052   // @FIXME: Ideally we want this to be explicit, but cannot be explicit,
0053   // because using an explicit constructor and a deduction guide leads to
0054   // a SEGFAULT in GCC11 (an up?). Re-evaluate down the line
0055   /* explicit */ ValueHolder(T&& _val) : val{std::move(_val)} {}
0056 
0057   // Does it make sense to allow copy operations?
0058 
0059   const T& operator*() const { return val; }
0060   T& operator*() { return val; }
0061 
0062   const T* operator->() const { return &val; }
0063   T* operator->() { return &val; }
0064 };
0065 
0066 }  // namespace Acts::detail