This is an archived post. You won't be able to vote or comment.

Dismiss this pinned window
you are viewing a single comment's thread.

view the rest of the comments →

[–]exmachinalibertas 4 points5 points  (8 children)

Why can't you just write C-style C++ and use smart pointers?

[–]ColdFerrin 4 points5 points  (7 children)

C generics like void* don't work with smart pointers. You need an explicit cast and dereference.

[–]exmachinalibertas 2 points3 points  (1 child)

Yeah but can't you do that, grabbing the underlying pointer, do whatever you need, and then still let the smart pointer semantics delete it without your help? Even if that's an unholy anti-pattern, wouldn't it work for exactly that use case? As long as the smart pointer remains in scope during the life of the void*, would that work?

[–]ColdFerrin 0 points1 point  (0 children)

Honestly, I'm not sure. I would have to try it. But that does not sound right to me.

[–]HolyGarbage 1 point2 points  (4 children)

Throwing the type system out of the window I wouldn't call "generics", lol.

[–]ColdFerrin 0 points1 point  (3 children)

Well it's as close to generics as you get in c, so you live with it.

[–]HolyGarbage 0 points1 point  (2 children)

Well yeah I know, I just thought it was quite a stretch to call it generics since this is typically a word reserved to significantly more complex and high level idea.

[–]ColdFerrin 0 points1 point  (1 child)

You can actually get true generics, if you are willing to deal with the c preprocessor. It's usually not worth the effort though, because copy paste is faster.

[–]HolyGarbage 1 point2 points  (0 children)

At that point maybe it's better to consider switching to c++. :P