4 ms·
Just have the non-throwing private constructor take the data member by rvalue reference and move them in place. This works in practice for so many projects that
by varajelle 5y ago
Just have the non-throwing private constructor take the data member by rvalue reference and move them in place.
This works in practice for so many projects that do C++ without exceptions.
- jcelerier 5y agoBut then you loose so many features of C++. Can't have aggregates anymore since everything needs private constructors -> more code -> more bugs. Each possible contructor now needs a matching static method. Can't put things in standard containers unless you rewrite all copy / move contructors (and you didn't forget to mark your move constructor noexcept, did you ?). What happens when you have classes with more than 3 members ? Constructors with 12 arguments ? That's unambiguously terrible, and does not even save you from exceptions coming from C++ itself. If 79% of surveyed C++ projects can use exceptions (https://www.jetbrains.com/lp/devecosystem-2020/cpp/ https://www.jetbrains.com/lp/devecosystem-2020/cpp/), likely so can you.