-
Strongly prefer C++ standard library facilities over C library functions, unless the latter absolutely cannot be avoided. In particular, aim to avoid all memory and string handling by C functions.
Example:
-
std::memcpy()should be usually replaced by a call tostd::copy(). The latter optimizes down to astd::memcpy()call in cases where POD types are to be copied, and is applicable in more situations (e.g. involving non-trivial copy constructors). -
String handling should be done by using
std::string. Avoid usingconst char*solutions and the use of any of the unsafestr*functions, unless there is a proven need to due performance considerations. This should be a very rare case.
-
-
Do not use the old C facilities (
rand(),RAND_MAX) for random number generation, since they give no guarantees on the quality of the randomness of the generated values, which can be arbitrarily bad. Usestd::mt19937(Mersenne Twister) from<random>by default, and other generators if you can justify their use overstd::mt19937. -
Do not use any of the following standard library functions, since they are officially removed from C++ 17 with the adoption of N4190:
auto_ptr<>,random_shuffle(),ptr_fun(),mem_fun(),mem_fun_ref(),bind1st(),bind2nd(),unary_function,binary_function.