My Project
Functions
addressof.hpp File Reference

Go to the source code of this file.

Functions

template<typename T >
constexpr T * bsl::addressof (T &val) noexcept
 Obtains the actual address of the object or function arg, even in presence of overloaded operator& (i.e., this should be used to get the address of an object instead of using & as that could be unsafe). More...
 
template<typename T >
T const * bsl::addressof (T const &&val)=delete
 Prevents the user from getting an address to a const as that would allow you to get the address of an rvalue which could result in UB. More...
 

Detailed Description

Function Documentation

◆ addressof() [1/2]

template<typename T >
constexpr T* bsl::addressof ( T &  val)
noexcept

Obtains the actual address of the object or function arg, even in presence of overloaded operator& (i.e., this should be used to get the address of an object instead of using & as that could be unsafe).

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_addressof_overview() noexcept
{
bool const mydata{};
if (bsl::addressof(mydata) == &mydata) {
bsl::print() << "success\n";
}
}
}
Template Parameters
Tthe type of object to get the address of.
Parameters
valthe object of type T to get the address of.
Returns
Returns the address of val

◆ addressof() [2/2]

template<typename T >
T const* bsl::addressof ( T const &&  val)
delete

Prevents the user from getting an address to a const as that would allow you to get the address of an rvalue which could result in UB.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_addressof_overview() noexcept
{
bool const mydata{};
if (bsl::addressof(mydata) == &mydata) {
bsl::print() << "success\n";
}
}
}
Template Parameters
Tthe type of object to get the address of.
Parameters
valthe object of type T to get the address of.
Returns
Returns the address of val