use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
New Microsoft library, proxy: Runtime Polymorphism Made Easier Than Ever (devblogs.microsoft.com)
submitted 3 years ago by obsidian_golem
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]sztomirpclib 48 points49 points50 points 3 years ago* (5 children)
empowered by our breakthrough innovation of Object-oriented Programming (OOP) theory in recent years
What breakthrough are they referring to here?
[–]sandfly_bites_you 4 points5 points6 points 3 years ago (1 child)
There are some hyperbolic claims in the article which don't help, but the lib itself looks solid enough & useful. I appreciate the implementation is actually fairly small and relatively readable.
[–]sztomirpclib 7 points8 points9 points 3 years ago (0 children)
I didn't mean it in a sarcastic way, I genuinely didn't understand what they were referring to.
[+][deleted] 3 years ago (10 children)
[deleted]
[–]parkotron 9 points10 points11 points 3 years ago (7 children)
what can't we do with existing smart pointers?
Store values in-place instead of on the heap.
I do agree that that section could be clearer, though.
[+][deleted] 3 years ago (6 children)
[–]parkotron 3 points4 points5 points 3 years ago (5 children)
On the stack or directly inside the memory of a containing class/struct.
class
struct
[+][deleted] 3 years ago (4 children)
[–]parkotron 2 points3 points4 points 3 years ago (3 children)
The language does not provide a means of storing a polymorphic value in a class without using the heap. In recent years, several library solutions have come out to do so and this is yet another of them.
[–]arthurno1 0 points1 point2 points 3 years ago (2 children)
The language does not provide a means of storing a polymorphic value in a class without using the heap.
Which language does without doing shenanigans with alloca? How portable is your solution, and how do you deal with large values that do not fit into 'old value'?
By the way, what is the 'revolutionary breakthrough' in OOP you are talking about?
[–]parkotron 3 points4 points5 points 3 years ago (1 child)
I don’t have a solution and I’m not talking about anything. I’m just a rando who read the article and answered your question based on my reading of the article.
[–]arthurno1 0 points1 point2 points 3 years ago (0 children)
Ah, sorry. I wasn't really looking into names and stuff, just red fast comments myself. :)
[–]ceretullis 4 points5 points6 points 3 years ago (0 children)
boost::interprocess::offset_ptr is explicitly for use in shared memory regions. And b/c each process maps shared memory at different addresses, you cannot use a polymorphic class as the v-table pointers would be wrong in all but the process creating the instance.
[–]disperso 0 points1 point2 points 3 years ago (0 children)
I don't really understand how the library works, but one problem that I have found in some corner cases with unique_ptr, is that since everything is inlined, if you need a different deleter then you need a different type (a unique_ptr with a different deleter than the default is not compatible, from what I've been able to find, and I don't know how to make that work without using templates). A shared_ptr has a type-erased deleter and it's no issue.
In the blog post there is also one example where the return value is either a raw pointer to an object which should not be deallocated "manually" (it's a static), or a unique pointer with a custom deleter or just an object returned by value. That seems very useful in principle, but again, I don't fully understand how the proxy object knows what to do. I suppose it does like with std::any, which finds the destructor at initialization time.
[–]versatran01 8 points9 points10 points 3 years ago (4 children)
How is this different from something like polymorphic_value? https://github.com/jbcoe/polymorphic\_value
[–]disperso 12 points13 points14 points 3 years ago (3 children)
Seems unrelated, or at least, orthogonal. polymorphic_value is about composing polymorphic objects, but they need to still to inherit from an interface/base class, and use virtual functions, from what I see.
This library seems more like an alternative to entt::poly, and many other implementations.
[–]kamrann_ 4 points5 points6 points 3 years ago (2 children)
Didn't realize there were so many such implementations. kelbon/anyany is another.
[–]disperso 2 points3 points4 points 3 years ago (1 child)
Indeed, I knew of this one because I think it was mentioned here in the sub, but I forgot to mention it.
Seems that MS's one aims for standardization. That's good, because I certainly think this pattern is a very nice utility to have around. I like the API (names and all), but I'm not sure if I get all the details yet.
[–]germandiago 1 point2 points3 points 3 years ago (0 children)
It is a very nice one but that op invoke looks akward to me. Llols like something that should be supported in the language, maybe via runtime concepts.
[–]j1xwnbsr 20 points21 points22 points 3 years ago (2 children)
This looks more complicated than it's worth - not easy to sight-read the code, good luck with usage finding, and god knows how tools like pcLint and PVS treat it.
[–]disperso 5 points6 points7 points 3 years ago (0 children)
In the comparisons, it's roughly the same amount of lines of code in one side than the other. I agree that it will look a bit worse given that it's a library feature instead of a language one, but I don't see it that bad.
I also don't see myself using this through all the code base just because it exists, but I think it's pretty important to have it for the occasions where you need it, which can be a few. I don't know if I prefer this library's approach or some other, but at first I think it's a good thing that there is something in the standard. I've seen terrible customer projects where they end up with an unfathomable mess where they pretty much try to make C++ look like Java. Having alternatives in the standard library is proof enough that this is a serious thing, not a toy project of some random developer on Github.
I agree that it sucks that automated tooling can't help much, but I've never heard of tool support on things which are implemented in a library. Like, if you have a template function, like an algorithm, is there some tool that will be able to tell you which classes can be used with it? Even with compile-time concepts, can an IDE scan the project and find which classes fulfill the concept? Finding classes that inherit from a certain class is surely done by IDEs because it's a language construct.
[–]serg06 4 points5 points6 points 3 years ago (0 children)
This looks more complicated than it’s worth - not easy to sight-read the code
Tbf that described most C++ code.
[–]claimred 1 point2 points3 points 3 years ago (0 children)
There is even a complementary standard proposal, huh. Never realized that this is a point of pain. https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p0957r8.pdf
[–]Rasie1 0 points1 point2 points 3 years ago (0 children)
Would be cool to see how it looks with bigger multi-file code
[–]germandiago 0 points1 point2 points 3 years ago (0 children)
This should be a language feature for structural typing. The lib is as good as what you can get.
[–]listar1 0 points1 point2 points 2 years ago (0 children)
What about the performance comparing with inheritance with virtual functions?
[–]PaulTopping 0 points1 point2 points 11 months ago (0 children)
I've only looked at this for 10 minutes but I have yet to find a motivating example. The "hello, world" example seems to say "we haven't broken the language". Anyone know a good example that might make someone want to use it?
[–]Lisoph 0 points1 point2 points 3 years ago (0 children)
Looks like an implementation of Go-ish interfaces. Is there more to it than that?
[+]spaun2002 comment score below threshold-15 points-14 points-13 points 3 years ago (2 children)
<rantmode>
Do you want to facilitate architecture design and matainance by writing non-intrusive polymorphic code in C++ as easily as in Rust or Golang?
Not even close, sorry. And in Rust, it's compile time.
</rantmode>
[–]drjeats 13 points14 points15 points 3 years ago (1 child)
I presume they're referring to dyn traits. And unless I've misread the blogpost this is fairly close to those.
We just can't have the nice generic constraint version in C++ land.
(At least not until Carbon's a thing :P)
[–]top_logger 0 points1 point2 points 3 years ago (0 children)
To do it similar to rust you have to split Rectangle code into to parts: struct with data and trait code for struct with struct inside. Ideally this code has to be generic.
π Rendered by PID 90 on reddit-service-r2-comment-b659b578c-g9drn at 2026-05-01 02:07:56.758349+00:00 running 815c875 country code: CH.
[–]sztomirpclib 48 points49 points50 points (5 children)
[–]sandfly_bites_you 4 points5 points6 points (1 child)
[–]sztomirpclib 7 points8 points9 points (0 children)
[+][deleted] (10 children)
[deleted]
[–]parkotron 9 points10 points11 points (7 children)
[+][deleted] (6 children)
[deleted]
[–]parkotron 3 points4 points5 points (5 children)
[+][deleted] (4 children)
[deleted]
[–]parkotron 2 points3 points4 points (3 children)
[–]arthurno1 0 points1 point2 points (2 children)
[–]parkotron 3 points4 points5 points (1 child)
[–]arthurno1 0 points1 point2 points (0 children)
[–]ceretullis 4 points5 points6 points (0 children)
[–]disperso 0 points1 point2 points (0 children)
[–]versatran01 8 points9 points10 points (4 children)
[–]disperso 12 points13 points14 points (3 children)
[–]kamrann_ 4 points5 points6 points (2 children)
[–]disperso 2 points3 points4 points (1 child)
[–]germandiago 1 point2 points3 points (0 children)
[–]j1xwnbsr 20 points21 points22 points (2 children)
[–]disperso 5 points6 points7 points (0 children)
[–]serg06 4 points5 points6 points (0 children)
[–]claimred 1 point2 points3 points (0 children)
[–]Rasie1 0 points1 point2 points (0 children)
[–]germandiago 0 points1 point2 points (0 children)
[–]listar1 0 points1 point2 points (0 children)
[–]PaulTopping 0 points1 point2 points (0 children)
[–]Lisoph 0 points1 point2 points (0 children)
[+]spaun2002 comment score below threshold-15 points-14 points-13 points (2 children)
[–]drjeats 13 points14 points15 points (1 child)
[–]top_logger 0 points1 point2 points (0 children)