Hmm. Do people use PIMPL that much (I have used it, but rarely) that we need std library support (and testing, documentation, understanding)? Just asking.
The PImpl idiom and the C++26 std:indirect type
91–100 of 122 posts
Re: The PImpl idiom and the C++26 std:indirect type
#92Re: The PImpl idiom and the C++26 std:indirect type
#93I have a little class called EImpl that is kind of like std::indirect except that it embeds the impl instead of pointing to it. It takes three template parameters: an embedded struct, a size and an alignment. It static_asserts that the embedded struct fits in the size and alignment, and it embeds it with approximately zero overhead. It’s about as easy to use as any other pImpl technique.
Re: The PImpl idiom and the C++26 std:indirect type
#94Earlier quoted context omitted.
where "more and more complex" do u see in this article? This is a basic C++ idiom, which constantly used by developers
I think the parent's point is that we started with raw pointers to implement PIMPL, then we had std::unique_ptr, and now we have std::indirect. So there are now three different ways how PIMPL can be implemented, each has its gotcha's and subtle differences that one needs to keep in mind. In large codebases you will now have to deal with all three solutions being used, depending on how old the code is.
Re: The PImpl idiom and the C++26 std:indirect type
#95Earlier quoted context omitted.
The irony is that including/using many standard c++ headers is far far more expensive than including a lean windows.h these days. To make hobby-coding fun, i use a mstdp.hpp that implements "naive" versions of unique,shared,function,etc that compiles faster than including just one of the std versions (and yes, MSVC versions of those libraries seem to be excessivly complex).
Not when using modules, which I have moved into on hobby projects. The import std is much faster than plain #include .
Maybe it's time to move my hobby project over and see how well it works.
Re: The PImpl idiom and the C++26 std:indirect type
#96Earlier quoted context omitted.
Not when using modules, which I have moved into on hobby projects. The import std is much faster than plain #include .
This is a fair point. Last time I tried modules in anger, it wasn't viable. Cmake didn't support them (well, they were experimental), intellisense didn't work and there were many ICE's in MSVC. Maybe it's time to move my hobby project over and see how well it works.
Best experience is VC++ with MSBuild, cmake/ninja work great with latest clang however import std support is not yet enabled by default in CMake.
I only care about VC++ for hobby coding, hence using modules.
See for example, https://github.com/pjmlp/RaytracingWeekend-CPP
Re: The PImpl idiom and the C++26 std:indirect type
#97Earlier quoted context omitted.
I'm interesting which C++ features also helps you to design such systems. I think basic RAII/function overloading/templates should give a lot of capabilities comparing with plain C? > (as opposed to using plain C) Also, curious - how plain C helps with this?
I've found that RAII and the stuff you have to buy into in order to use RAII come with more downsides than upsides once you scale beyond high level programs that try to get done a lot with very few lines. > how plain C helps with this? By staying out of the way and providing everything of what you actually need in the end. That is assuming a detail oriented approach where you deeply think about, and want to be flexib…
Re: The PImpl idiom and the C++26 std:indirect type
#98> Never null: it always holds a value, except in the moved-from state I am wondering why C++ can't implement "non-null" unique_ptr version in the same way? As I know, that the main argument against implementing it is, that it's can't be done, since move-out unique_ptr still can be null.
Re: The PImpl idiom and the C++26 std:indirect type
#99I have a little class called EImpl that is kind of like std::indirect except that it embeds the impl instead of pointing to it. It takes three template parameters: an embedded struct, a size and an alignment. It static_asserts that the embedded struct fits in the size and alignment, and it embeds it with approximately zero overhead. It’s about as easy to use as any other pImpl technique.
But if the pimpl size grows too big, you're forced to break ABI? And before it grows too big, it wastes memory. For your use cases it may not matter, and the saved pointer indirection may be more important, but maybe the person who has a million item vector of objects doesn't appreciate a 300% "just in case" memory overhead. The overhead may also hurt cache hits. If you're doing this to save the pointer indirection,…
how it wastes the memory? It's just a bytes array of the same size as struct. I would be more imposed on how idiomatic pimpl with heap allocation influences memory usage and cache hits