Merge master into windows.
Use different maximum integer for Visual C++.

MSVC doesn't treat std::numeric_limits<T>:max() as a compile-time constant.

(cherry picked from commit 2e9cc3209d7b6eef2a4a6b9224d592f821b1712d)