Summary
This episode introduces C++20's new capability to perform dynamic memory allocation in compile-time constexpr contexts. Jason demonstrates how you can use operator new and delete within constexpr functions with specific constraints: all allocated memory must be freed before returning, memory can't be accessed after deallocation, and pointers to heap memory cannot escape the constexpr context. While initially limited, this paves the way for using containers like std::vector and std::string in constexpr functions.
Related C++ Standard Sections
This episode covers topics found in these sections of the C++ standard:
-
[unique.ptr.dltr.dflt]52% match -
[basic.stc.dynamic.general]51% match -
[ptr.launder]49% match