Why was std::pow(double, int) removed from C++11?

double pow(double, int); hasn’t been removed from the spec. It has simply been reworded. It now lives in [c.math]/p11. How it is computed is an implementation detail. The only C++03 signature that has changed is: float pow(float, int); This now returns double: double pow(float, int); And this change was done for C compatibility. Clarification: 26.8 … Read more

std::lexical_cast – is there such a thing?

Only partially. C++11 <string> has std::to_string for the built-in types: [n3290: 21.5/7]: string to_string(int val); string to_string(unsigned val); string to_string(long val); string to_string(unsigned long val); string to_string(long long val); string to_string(unsigned long long val); string to_string(float val); string to_string(double val); string to_string(long double val); Returns: Each function returns a string object holding the character representation … Read more

Why isn’t there int128_t?

I’ll refer to the C standard; I think the C++ standard inherits the rules for <stdint.h> / <cstdint> from C. I know that gcc implements 128-bit signed and unsigned integers, with the names __int128 and unsigned __int128 (__int128 is an implementation-defined keyword) on some platforms. Even for an implementation that provides a standard 128-bit type, … Read more

Assign a nullptr to a std::string is safe?

Interesting little question. According to the C++11 standard, sect. 21.4.2.9, basic_string(const charT* s, const Allocator& a = Allocator()); Requires: s shall not be a null pointer. Since the standard does not ask the library to throw an exception when this particular requirement is not met, it would appear that passing a null pointer provoked undefined … Read more

C++ std::vector vs array in the real world

A: Almost always [use a vector instead of an array]. Vectors are efficient and flexible. They do require a little more memory than arrays, but this tradeoff is almost always worth the benefits. That’s an over-simplification. It’s fairly common to use arrays, and can be attractive when: the elements are specified at compile time, e.g. … Read more

tech