Namespaces
Variants
Views
Actions

voidify

From cppreference.com
< cpp‎ | memory
 
 
Utilities library
Language support
Type support (basic types, RTTI)
Library feature-test macros (C++20)
Dynamic memory management
Program utilities
Coroutine support (C++20)
Variadic functions
Debugging support
(C++26)
Three-way comparison
(C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)(C++20)(C++20)   
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)
Elementary string conversions
(C++17)
(C++17)

 
Dynamic memory management
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Allocators
Garbage collection support
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)



 
template< class T >
constexpr void* voidify( T& obj ) noexcept;
(since C++20)
(exposition only*)

Returns the address of obj (implicitly converted to void*).

Contents

[edit] Parameters

obj - the object whose address will be taken

[edit] Return value

std::addressof(obj)

[edit] Notes

This exposition-only function is introduced by P0896R4. It is used to describe the effects of uninitialized memory algorithms which construct objects in uninitialized memory areas. The result pointer is used as the placement-params of a placement new expression.

Initially, the return value was const_cast<void*>(static_cast<const volatile void*>(std::addressof(obj))), which breaks const-correctness. The explicit casts were removed by the resolution of LWG issue 3870, and the only conversion left is the implicit conversion to void*.

[edit] Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior
LWG 3870 C++20 the explicit casts broke const-correctness removed these casts

[edit] See also

copies a range of objects to an uninitialized area of memory
(function template) [edit]
copies an object to an uninitialized area of memory, defined by a range
(function template) [edit]
moves a range of objects to an uninitialized area of memory
(function template) [edit]
constructs objects by default-initialization in an uninitialized area of memory, defined by a range
(function template) [edit]
constructs objects by value-initialization in an uninitialized area of memory, defined by a range
(function template) [edit]
creates an object at a given address
(function template) [edit]