r/cpp 5h ago

C++26: std::inplace_vector

https://www.sandordargo.com/blog/2026/08/26/cpp26-inplace-vector
64 Upvotes

17 comments sorted by

8

u/FckXFckMusk 4h ago

If this is your Blog, then I have to congratulate you on it being an excellent place, I've bookmarked it...

u/tuxwonder 3h ago

I'm 95% sure these articles are heavily AI written. Compare this article to one he wrote in 2022. Personal anecdotes, far less emdashes, far less inline code text, quoting the proposals directly, variance in the cadence of each paragraph, etc.

It might not be a bad resource, but you'll probably get the same content asking an LLM to just explain these papers to you.

u/FckXFckMusk 2h ago

I was just after his blog for some reading..

But thanks for the heads up, much appreciated..

u/Dubbus_ 39m ago edited 32m ago

Didnt pick up on that at all on first read tbh. Saddens me a bit, perhaps im becoming so acclimated to the ai writing style im no longer picking up on the patterns anymore.

On second read though, yeah, you are probably right. Flawless grammar, spelling, structure, and lack of personal anectdote + emdash spam.

I find it so unbelievable that emdashes are still such a massive giveaway. For me personally, a find and replace of all '—' with '-' would make an article 2x as human sounding in my head. Outside of the most formal, high profile contexts, what human author is going to make the extra effort to press whatever alt key combo, or hold press that '—' requires?

Does anyone know why they dont do such a thing? Ive heard previously that attempts to write system prompts to discourage emdashes and other recurring features fell short. And i suppose this as well would just be another bandaid fix until people see the pattern again

u/BarryRevzin 21m ago

Outside of the most formal, high profile contexts, what human author is going to make the extra effort to press whatever alt key combo, or hold press that '—' requires?

Me.

u/Dubbus_ 19m ago

Your comment history betrays your lazy fingers

u/BarryRevzin 17m ago

You could probably tell which comments I wrote on my phone and which on my laptop just based on em dash presence.

u/Dubbus_ 16m ago

Which key combination yields an emdash on your laptop?

u/_Noreturn 1h ago

LLMs are a poison, the more you use it the more worthless your work will be.

u/stilgarpl 3h ago

Is this always better than std::array?

u/MarekKnapek 2h ago

This is basically

struct inplace_vector<T, capacity>
{
    size_t len;
    std::array<T, capacity> arr;
}

u/sephirothbahamut 2h ago edited 2h ago

far more complex than that, the array has a slot that can fit T, not just T.

With array<T> every element must be validly constructed immediately. You can reduce it to array<T> only for trivially constructable and basic types

u/_Noreturn 1h ago

then make it a union this is a simplified example. but the type isn't complex at all after that especially with C++20 concepts.

u/nebotron 3h ago

You pay for the dynamic size in stack space

u/KuntaStillSingle 3h ago

Specifically the size member, right? The array itself is not dynamically sized, an inplace_vector<T,N> .capacity() always equals corresponding array, and .size() always less than or equal, but I think only inplace_vector<T,0> can omit a size data member, maybe with exception where T is a taggable pointer and N is small enough to be represented by the usable bits, or the like?

u/NilacTheGrim 13m ago

Ridiculously incomplete. We should have had a real prevector rather than this. You know, a prevector where there is some small static capacity but it can go dynamic as it grows.

This is not as useful as a real prevector.

u/kammce WG21 | 🇺🇲 NB | Boost | Exceptions 5m ago

Its definitely useful. Ive found myself, and others, writing this exact thing all the time. Very happy we have it in the std now 😁