I've always avoided returning objects by value, due to copy-elision being an optimization with observable side-effects... but I've read that C++17 has added a way to ensure returned objects never call their copy constructor and destructor! Is there anything special I need to do in order to trigger this new behavior reliably?
I don't fully understand the rules around it, and it sounds easy to accidentally write a function that triggers the "old" behavior; I want to avoid that at all costs if possible. Generating a compiler error if the compiler lacks this guarantee, (or more realistically, if I mess it up) would grant me peace.
Is there any kind of boilerplate or habit, when coding my class or function, that'd let me absolutely avoid the pre-C++17 behavior?