template <std::size_t N>
struct raw {
template <typename U>
constexpr raw(U x, std::enable_if<.....>);
template <typename U>
constexpr operator U();
};
template <template ContainerType, typename T, std::enable_if<std::is_trivially_convertible<T, ....> > >
struct somewhat_erased_container : private ContainerType<raw<sizeof(T)>> {
};
It's particularly easy to do with containers of pointers (of course).Just getting started on it, it seems that the theme is that you can't have the same binary code work on different types without having a run-time indirection in there somewhere. But, you can use templates to keep that indirection convenient and type safe. And, you can structure your templates to only specialize a minimal amount of code necessary to interface your type into a non-specialized algorithm.
"you can't have the same binary code work on different types without having a run-time indirection in there somewhere"
That's certainly the case, but if you're passing by reference you already have an indirection, so that may or may not mean additional run-time overhead.
True, for embedded systems this can still be a painful waste... But I'd argue if that is the case, you probably should be very explicit about using/not using STL libraries.
It's fair that if you want to optimize startup times, that first page in hurts, although generally with C++ is's more about the symbol linking overhead than anything else (and there are a lot of strategies for minimizing that, but it sure isn't want happens by default).
Other than cache, there are plenty of tricks that can cure a lot of other ills, but cache is precious.
I have to say though, I've not seen too many cases where paging was caused by bloated object code size (lots of cases where it was caused by brutal bloat due to just outright bad code).
There was a time a couple of decades ago where it was a common issue with C++, but since then RAM has gotten a lot cheaper and C++ compilers/linkers have become much smarter (not to mention all compilers/linkers getting much smarter about code size). Sure, you can find pain points, but with a modicum of effort it's really hard to imagine a project really flapping outside the working set size purely due to the compiler/linker refusing to be drink from the water it has been lead to...
Upvoted anyway for precision.
In all serious though, swapping due to code bloat (as opposed to actual runtime bloat)... I haven't seen that in ages. Caches though... like a samurai with an absurdly sharp blade... they kill you almost every time, and usually you don't even know you're dead.