There was already a legal way to achieve this that everyone should already have been using (laundering a pointer through a no-op memmove). Using reinterpret_cast here is a bug.
The "start_lifetime_as" facility does one additional thing beyond providing a tidy standard name for the memory laundering incantation. Semantically it doesn't touch the memory whereas the no-op memmove intrinsically does. In practice, this makes little difference, since the compiler could see that the memmove was a no-op and optimized accordingly.
No because the object does not exist after std::launder. It only exists after std::start_lifetime_as. The bytes being there says nothing about the object, per the C++ standard.
The compiler will create an implicit lifetime type at the memmove destination as required to give it defined behavior. Technically you don't even need std::launder, it is just far more convenient than the alternative.
The cppreference description seems questionable to me:
> Implicitly creates a complete object of type T (whose address is p) and objects nested within it. The value of each created object obj of TriviallyCopyable type U is determined in the same manner as for a call to std::bit_cast<U>(E) except that the storage is not actually accessed, where E is the lvalue of type U denoting obj. Otherwise, the values of such created objects are unspecified.
So T is the complete new object. It contains subobjects, and one of those subobjects has type U. U is initialized as if by bit_cast, and I presume they meant to say that bit_cast casted from the bits already present at the address in question. Since “obj” is mentioned without any definition of any sort, I’ll assume it means something at the correct address.
But what’s E? The page says “E is the lvalue of type U denoting obj,” but obj probably has type char or a similar type, and if it already had type U, there would be no need for bit_cast.
Well, ignoring alignment restrictions, it depends on the implementation of read. If it is truly opaque, as far as the compiler is concerned, the kernel (or the network card or whatever) is truly constructing a Foo in that buffer, making the cast perfectly legitimate.
start_lifetime_as is useful when the buffer lifetime is transparent to the compiler and it can mess up aliasing assumptions.
> An object of dynamic type Tobj is type-accessible through a glvalue of type Tref if Tref is similar ([conv.qual]) to: Tobj, a type that is the signed or unsigned type corresponding to Tobj, or a char, unsigned char, or std :: byte type. If a program attempts to access ([defns.access]) the stored value of an object through a glvalue through which it is not type-accessible, the behavior is undefined.
The dynamic type of a char buffer is, well, a char buffer, and can only be accessed via things that are the same type as a char buffer up to signedness and cv-qualification. The actual strict aliasing rules are not commutative!
This gets to the heart of effective type rules, which are complex, confusing, and not properly implemented by compilers. C and C++ definitely diverge here, because C is less ambitious in its object model (which mean it just simply leaves so many details about it undiscussed).
Malloc returns memory that is uninitialized and has no type. The effective type of that memory is initialized on first use by C, whereas C++ relies on angelic nondeterminism to magically initialize the type at return type to whatever will work in the future.
> Malloc returns a buffer and then you cast it to the type you want.
You can’t cast the buffer — you’re casting the pointer.
One might argue (I’m not sure whether this is correct) that malloc allocated an array of ints and the language merely has no way to state that directly. Then you write to those ints using a char pointer, and then you access them as ints, but they’ve been ints ever since allocation.
If the type is an implicit-lifetime type, then you can legally create an unsigned char array, and then reinterpret_cast a pointer to that to a pointer to the type.
https://eel.is/c++draft/intro.object#15 is an example showing this with malloc; the subsequent paragraph further permits it to work with an unsigned char array.
> It solves the problem the originating user asked it to
Interesting. And is there a mechanism to go back and "fix" the tools after they are published? What happens if the tool decided to use the "id" attribute to click on buttons and now you have a new website that follows a different pattern to find the right target?
I agree that "correctness" of a tool could have different meaning depending on the context of the problem though (e.g. would you consider OOM a correctness bug even if it addresses the user's ask?)
The problem here is that N different users will ask for N different variants of the same tool, so you'll end up with a tool which is similar but not quite. Is the tool updated to support new functionality, or a new tool is created and you end up with N variants of a tool.
Everyone is just taking a round about way to get there. The workflow/program as "tools" approach is the right one. Agents skills are more or less in that same direction.
there are hundreds or thousands of 'memory' things ppl have been inventing. i am yet to see any proof that these are actually useful or have saved any tokens.
Do you all want to know a fun fact about adult-content startups:
Why do you think Onlyfans is the reigning platform for what it does.
Not because it's technically superior, or has the best advertising, or any other logical reason you might summon.
It's because they have a sweetheart deal with a payment processor (Stripe).
I put some time into seriously investigating what it'd take to get an adult-content platform off of the ground, here is one of the emails I received from a self-advertised "high-risk processor":
> "Yes, we do have some Payment Facilitator solutions. However, none of these processors will accept Adult content."
Nobody will touch it with a 10 foot pole. It's absolute bullshit and is ripe for disruption.
My sister and I received fresh oranges in our Christmas stockings every year. Along with nuts and chocolate and goodies like that. Of course, the "Christmas stocking" event was tied with St. Nicholas' Day on December 6, where it was traditional to place our shoes on the fireplace overnight, but the stockings were stretchy and higher-capacity than children's shoes!
Also, the fresh oranges were sort of ironic, because a tangerine tree grew in our backyard. I've always preferred tangerines.
Mom always packed fresh fruit with my school lunches. I had never heard or experienced the trading of food at lunch, and so I resorted to discarding the parts of lunch which I didn't want to eat. Oranges were the first to go. It wasn't the taste of oranges that I disliked, it was the stickiness and the labor involved in peeling them and getting past the rind and pith.
Biologics production is one of the industries that is ripe for a manufacturing breakthrough, and would greatly benefit humanity.
The current best option we have for combating heart disease and lowering cholesterol are monoclonal antibodies (PCSK9 inhibitors), and a similar trajectory is developing with sarcopenia and obesity biologics (Bimagrumab).
Manufacturability is treated as an afterthought right now, but as we’ve seen in other industries, if you can bring some of those constraints earlier into the process it can have serious economic implications.
The opportunity for manufacturing innovation is growing, as the next generation of monoclonal antibodies are even more difficult to produce at scale.
Nearly all zero-copy code that deals with external I/O buffers looks something like:
With this merged, swap the reinterpret_cast for start_lifetime_as and you're no longer being naughty.https://en.cppreference.com/cpp/memory/start_lifetime_as
reply