Great talk, I hadn't thought about the concept of pointer provenance before but it makes a lot of things click together now that just seemed like strange rules previously.
What if the constructor throws an exception in placement new when you reuse a pre-existing variable after calling std::destroy_at? Then the variable is not constructed and the destuctor will be called on a non-constructed storage😱 This isn't an exception-safe practice. Only use placement new on storage where the call to destructor isn't inevitable or the constructor is noexcept.
44:19 so, if I have a data structure with its values *scattered* across a single allocation, does it make sense do a (complicated) loop to start_lifetime_as for each of the value elements? I don’t mind doing it if the loop(s) is elided anyway, and if it improves the correctness of the code (i doubt the compiler will see into that much logic anyway to make my objects blessed, but ok). I could do a start_lifetime_as_array for the whole allocation but that seems an overkill too because not all memory will be having usable objects. Great talk!
Thanks! You don't necessarily need to call start_lifetime_as in a loop before, can't you just do it the first time you access the element? Unless you don't know when that happens. Alternatively, just calling start_lifetime_as_array is fine, it doesn't actually "do" anything, and it doesn't matter if you start the lifetime of types that aren't actual objects - they just have indeterminate values.
@@foonathan I think I am confused, this is for a container that doesn't initialize elements (doesn't do any work) if the default constructor is trivial. In the past, what is I did is to simply allocate (allocator.allocate) and then don't run any code in this memory in the constructor. Then I realized that I should at least start the lifetime. start_lifetime_as is an option I guess, but what I really need is that uninitialized_default_construct, but I also have to hope(?) that it compiles to nothing for trivial constructors. What was attractive of start_lifetime_as is that it wouldn't add any machine code.
Great talk!
Great talk, I hadn't thought about the concept of pointer provenance before but it makes a lot of things click together now that just seemed like strange rules previously.
What if the constructor throws an exception in placement new when you reuse a pre-existing variable after calling std::destroy_at? Then the variable is not constructed and the destuctor will be called on a non-constructed storage😱 This isn't an exception-safe practice. Only use placement new on storage where the call to destructor isn't inevitable or the constructor is noexcept.
44:19 so, if I have a data structure with its values *scattered* across a single allocation, does it make sense do a (complicated) loop to start_lifetime_as for each of the value elements? I don’t mind doing it if the loop(s) is elided anyway, and if it improves the correctness of the code (i doubt the compiler will see into that much logic anyway to make my objects blessed, but ok). I could do a start_lifetime_as_array for the whole allocation but that seems an overkill too because not all memory will be having usable objects.
Great talk!
Thanks!
You don't necessarily need to call start_lifetime_as in a loop before, can't you just do it the first time you access the element? Unless you don't know when that happens. Alternatively, just calling start_lifetime_as_array is fine, it doesn't actually "do" anything, and it doesn't matter if you start the lifetime of types that aren't actual objects - they just have indeterminate values.
@@foonathan I think I am confused, this is for a container that doesn't initialize elements (doesn't do any work) if the default constructor is trivial. In the past, what is I did is to simply allocate (allocator.allocate) and then don't run any code in this memory in the constructor. Then I realized that I should at least start the lifetime. start_lifetime_as is an option I guess, but what I really need is that uninitialized_default_construct, but I also have to hope(?) that it compiles to nothing for trivial constructors. What was attractive of start_lifetime_as is that it wouldn't add any machine code.
Pre compile time
and run time objs
31:51 🤓 this code also needs to verify that (this != &other)
12:24 ua-cam.com/video/6EOSRKMYCTc/v-deo.html