Loading...
Searching...
No Matches
proxymemberaccess.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_COMMON_PROXYMEMBERACCESS_HH
#define DUNE_COMMON_PROXYMEMBERACCESS_HH
#include <type_traits>
#include <utility>
namespace Dune {
namespace Impl {
// helper struct to store a temporary / proxy
// for the duration of the member access
template<typename T>
struct member_access_proxy_holder
{
// only support moving the temporary into the holder object
member_access_proxy_holder(T&& t)
: _t(std::move(t))
{}
// The object is fundamentally a temporary, i.e. an rvalue,
//
const T* operator->() const
{
return &_t;
}
T _t;
};
} // end Impl namespace
#ifdef DOXYGEN
template<typename T>
pointer_or_proxy_holder
handle_proxy_member_access(T&& t);
#else // DOXYGEN
// This version matches lvalues (the C++ type deduction rules state that
// the T&& signature deduces to a reference iff the argument is an lvalue).
// As the argument is an lvalue, we do not have to worry about its lifetime
// and can just return its address.
template<typename T>
inline typename std::enable_if<
std::is_lvalue_reference<T>::value,
typename std::add_pointer<
typename std::remove_reference<
T
>::type
>::type
>::type
handle_proxy_member_access(T&& target)
{
return &target;
}
// This version matches rvalues (the C++ type deduction rules state that
// the T&& signature deduces to a non-reference iff the argument is an rvalue).
// In this case, we have to capture the rvalue in a new object to make sure it
// is kept alive for the duration of the member access. For this purpose, we move
// it into a member_access_proxy_holder instance.
template<typename T>
inline typename std::enable_if<
!std::is_lvalue_reference<T>::value,
Impl::member_access_proxy_holder<T>
>::type
handle_proxy_member_access(T&& target)
{
return {std::forward<T>(target)};
}
#endif // DOXYGEN
} // namespace Dune
#endif // DUNE_COMMON_PROXYMEMBERACCESS_HH
Dune::handle_proxy_member_access
pointer_or_proxy_holder handle_proxy_member_access(T &&t)
Transparent support for providing member access to both lvalues and rvalues (temporary proxies).
Dune::operator->
constexpr pointer operator->() const
Arrow access to members of referenced value.
Definition iteratorfacades.hh:1129
Dune::type
MPI_Datatype MPITraits< ParallelLocalIndex< T > >::type
Definition plocalindex.hh:317
Dune
Dune namespace
Definition alignedallocator.hh:13
Dune::type