DUNE PDELab (git)

memory.hh
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
13namespace Dune::Std {
14
15#if __cpp_lib_to_address >= 201711L
16
17using std::to_address;
18
19#else
20
21namespace Impl {
22
23template <class T>
24constexpr T* toAddressImpl (T* p, Dune::PriorityTag<2>) noexcept
25{
26 static_assert(!std::is_function_v<T>);
27 return p;
28}
29
30template <class T>
31constexpr auto toAddressImpl (const T& p, Dune::PriorityTag<1>) noexcept
32 -> decltype(std::pointer_traits<T>::to_address(p))
33{
34 return std::pointer_traits<T>::to_address(p);
35}
36
37template <class T>
38constexpr 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
46template <class T>
47constexpr 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: default_accessor.hh:10
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
Helper class for tagging priorities.
Definition: typeutilities.hh:87
Helper class for tagging priorities.
Definition: typeutilities.hh:73
Utilities for type computations, constraining overloads, ...
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)