Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. C/C++
  4. Memory & storage
  5. pw_memory

Overview

Memory utilities.

Functions

template<typename T , typename... Args, typename = std::enable_if_t<!std::is_array_v<T> || std::extent_v<T> != 0>, typename = decltype(::new (std::declval<void*>()) T(std::declval<Args>()...))>
T * pw::construct_at (T *location, Args &&... args)
 

Function Documentation

◆ construct_at()

template<typename T , typename... Args, typename = std::enable_if_t<!std::is_array_v<T> || std::extent_v<T> != 0>, typename = decltype(::new (std::declval<void*>()) T(std::declval<Args>()...))>
T * pw::construct_at ( T *  location,
Args &&...  args 
)

Constructs a T object initialized with args at location without allocating memory.

Backports C++20's std::construct_at so C++17-compatible code can perform constexpr in-place construction when compiled as C++20 or newer.

Template Parameters
TThe non-cv-qualified, non-array object type to construct.
ArgsArgument types forwarded to T's constructor.
Parameters
[out]locationPointer to uninitialized storage suitable for T.
[in]argsArguments forwarded to T's constructor.
Returns
location.