What is std::decay and when it should be used?

<joke>It’s obviously used to decay radioactive std::atomic types into non-radioactive ones.</joke> N2609 is the paper that proposed std::decay. The paper explains: Simply put, decay<T>::type is the identity type-transformation except if T is an array type or a reference to a function type. In those cases the decay<T>::type yields a pointer or a pointer to a … Read more

What is the purpose of the div() library function?

From the C99 Rationale document: (7.20.6.2 The div, ldiv, and lldiv functions) Because C89 had implementation-defined semantics for division of signed integers when negative operands were involved, div and ldiv, and lldiv in C99, were invented to provide well-specified semantics for signed integer division and remainder operations. The semantics were adopted to be the same … Read more

stdio.h not standard in C++?

stdio.h is standard, but deprecated. Always prefer cstdio in C++. [n3290: C.3.1/1]: For compatibility with the Standard C library, the C++ standard library provides the 18 C headers (D.5), but their use is deprecated in C++. [n3290: D.5/3]: [ Example: The header <cstdlib> assuredly provides its declarations and definitions within the namespace std. It may … Read more

Why isn’t `int pow(int base, int exponent)` in the standard C++ libraries?

As of C++11, special cases were added to the suite of power functions (and others). C++11 [c.math] /11 states, after listing all the float/double/long double overloads (my emphasis, and paraphrased): Moreover, there shall be additional overloads sufficient to ensure that, if any argument corresponding to a double parameter has type double or an integer type, … Read more

How to access a standard-library module in Python when there is a local module with the same name?

You are looking for Absolute/Relative imports from PEP 328, available with 2.5 and upward. In Python 2.5, you can switch import‘s behaviour to absolute imports using a from __future__ import absolute_import directive. This absolute- import behaviour will become the default in a future version (probably Python 2.7). Once absolute imports are the default, import math … Read more