Open trcrsired opened 1 month ago
new
and delete
during constant evaluation works fine in freestanding. Those are only a problem if they leak into runtime. There's discussion of keeping constexpr new and delete working in https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2013r5.html .
For std::allocator, I'm working on making that consteval in freestanding: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3295r0.html
I'm still working through a prototype implementation. I'm hoping that paper will make it into C++26, but it will be tight.
i am talking about operator new. not new. Since I need to allocate raw memory for vector in constexp context for freestanding. I do not and cannot use std::allocator
If std::allocator isn't an option, then what do you use in hosted environments during constant evaluation?
Another potential alternative for you is to use the new[] operator to allocate union {char c; T t;}, then change the active member rather than do an in place construction. I think that prevents you from implementing .data(), but you can still get a useful constexpr vector.
My previous answer is still the long term answer though.
std::allocator is not freestanding and there is no way to allocate heap memory in constexpr either. Do you have a solution?