Can the mighty mastodonverse help me?
i'm doing some teaching lessons and i can't think of an good example for function in c++ that have different implementations for "by ref" and "by val" for function parameters.
i have enough for each, but not one example where both version would be relevant.
=> More informations about this toot | More toots from sickeroni@mastodon.social
@sickeroni
Shall they have the same or similar semantics?
This reminds me of utilities like boost::trim
. Calling by value could return a trimmed copy while calling by reference would trim in-place.
=> More informations about this toot | More toots from dermojo@hachyderm.io
@dermojo mhh i need to take a deeper lok in it. I read your explaination, but couldn't see it in code. but maybe i just need a small break :D
=> More informations about this toot | More toots from sickeroni@mastodon.social
@sickeroni @dermojo Shouldn't be the distinction more along the line of object independence, and the rest follows from there?
You have two cases:
I hope this leads you to an example that demonstrates your teaching intent.
[#]cpp
=> More informations about this toot | More toots from DanielaKEngert@hachyderm.io
@DanielaKEngert @sickeroni @dermojo
very nice categorization that i will steal for my teaching.
one thing is missing wrt references: dynamic polymorphism with virtual requires them.
=> More informations about this toot | More toots from PeterSommerlad@mastodon.social
@PeterSommerlad @sickeroni @dermojo That's very much true, but I refrained from digging into this rabbit-hole because I didn't get the impression that Paul was looking after that 😀
Thank you for your blessing 😎
=> More informations about this toot | More toots from DanielaKEngert@hachyderm.io
@DanielaKEngert @sickeroni @dermojo assuming the same method signature - the use case matters,too. Using a do_something(const auto& x) is fine until you step into the land of parallel processing (combined with the use of std::generator I promise ugly runtime problems) and this is prevented by a local copy using do_something (val) - dangling references are nasty
=> More informations about this toot | More toots from BLeichtle@sueden.social This content has been proxied by September (3851b).Proxy Information
text/gemini