dune-common  2.11
memory.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 // SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5 #ifndef DUNE_COMMON_STD_MEMORY_HH
6 #define DUNE_COMMON_STD_MEMORY_HH
7 
8 #include <memory>
9 #include <type_traits>
10 
12 
13 namespace Dune::Std {
14 
15 #if __cpp_lib_to_address >= 201711L
16 
17 using std::to_address;
18 
19 #else
20 
21 namespace Impl {
22 
23 template <class T>
24 constexpr T* toAddressImpl (T* p, Dune::PriorityTag<2>) noexcept
25 {
26  static_assert(!std::is_function_v<T>);
27  return p;
28 }
29 
30 template <class T>
31 constexpr auto toAddressImpl (const T& p, Dune::PriorityTag<1>) noexcept
33 {
35 }
36 
37 template <class T>
38 constexpr auto toAddressImpl (const T& p, Dune::PriorityTag<0>) noexcept
39 {
40  return toAddressImpl(p.operator->(), Dune::PriorityTag<3>{});
41 }
42 
43 } // end namespace Impl
44 
46 template <class T>
47 constexpr auto to_address(T&& p) noexcept
48 {
49  return Impl::toAddressImpl(std::forward<T>(p), Dune::PriorityTag<3>{});
50 }
51 
52 #endif
53 
54 } // end namespace Dune::Std
55 
56 #endif // DUNE_COMMON_STD_MEMORY_HH
Namespace for features backported from new C++ standards.
Definition: algorithm.hh:19
Utilities for type computations, constraining overloads, ...
Helper class for tagging priorities.
Definition: typeutilities.hh:86
Helper class for tagging priorities.
Definition: typeutilities.hh:72
constexpr auto to_address(T &&p) noexcept
Obtain the address represented by p without forming a reference to the object pointed to by p...
Definition: memory.hh:47