Got a code snippet? :v
-
-
Replying to @slurpsmadrips
Already left work but here's something I'm typing on my phone: void dostuff(Bar &bar) { // Foo need not last after this function Foo f(bar); // ... } I want a way to make bar into a pointer that can be null. I want f to become a pointer that is null if bar is null.
3 replies 0 retweets 1 like -
Replying to @Sunjay03 @slurpsmadrips
Oh and I want everything to stay on the stack. So far I'm having to use new/delete which really sucks. I can't even use a smart pointer because that has a different type.
1 reply 0 retweets 0 likes -
Replying to @Sunjay03
Why not use a unique pointer with a custom Deleter and a ::pointer to keep the types compatible? You could also do some magic with placement new
1 reply 0 retweets 0 likes -
Replying to @slurpsmadrips
That would definitely solve the problem of having to add delete everywhere (this is very branchy code), but it doesn't help the fact that it's heap allocated. I'd be adding a lot of complexity without really getting the code I'm after
2 replies 0 retweets 0 likes -
Replying to @Sunjay03 @slurpsmadrips
(I'm fairly confident that there is no nice way to express what I want in C++ so I'm pretty resigned to my new/delete solution even though it isn't great)
1 reply 0 retweets 0 likes -
Replying to @Sunjay03
Mmmmm i dunno about that. c++ can’t express reflection and regular void and that’s about it. If you want me to sign an NDA or something I bet I could help out with this ;)
1 reply 0 retweets 1 like -
Replying to @slurpsmadrips
Hehe I'm sure we could come up with something a little complicated that fixes the issue. I'm more sad that I can't just write this code in a straightforward way
1 reply 0 retweets 0 likes -
Replying to @Sunjay03 @slurpsmadrips
Forgive me if this is stupid, but is there a reason you can't use `std::optional<&Bar>` here?
2 replies 0 retweets 0 likes -
two reasons 1) &Bar is not how references are written in C++ :v 2) std::optional<T&> doesn't exist because some people on the committee are VERY MAD about "rebinding references", despite us already having types in C++ that do this.
2 replies 0 retweets 3 likes
Listen I wrote c++ like twice and it convinced me to write Rust so you cant expect these ridiculous things like knowing the most basic syntax before chiming in :trollface:
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.