fix(StaticString): add a workaround for MSVC 2015 on int constructor

This commit is contained in:
Ronan Abhamon 2018-05-21 11:53:19 +02:00
parent 5b9c76ff31
commit 130d199e6e

View file

@ -111,18 +111,16 @@ namespace Private {
RawStaticString<N> raw;
private:
template<typename T>
static constexpr bool testInt (T n) {
// Do not use it directly in the two enable_if below. (MSVC 2015 bug.)
return n < 0;
}
// Workaround for MSVC 2015.
// See: https://stackoverflow.com/questions/41593649/why-wont-visual-studio-let-me-use-a-templatized-constexpr-function-in-enable-i/41597153
struct IsNeg { static const bool value = Value < 0; };
template<std::size_t... Index, typename Int = int, typename std::enable_if<!testInt<Int>(Value), int>::type* = nullptr>
template<std::size_t... Index, typename Int = int, typename std::enable_if<!IsNeg::value, Int>::type* = nullptr>
constexpr StaticIntStringHelper (const IndexSequence<Index...> &) :
raw{ char('0' + Value / pow10(N - Index - 2) % 10)..., '\0' } {}
template<std::size_t... Index, typename Int = int, typename std::enable_if<testInt<Int>(Value), int>::type* = nullptr>
constexpr StaticIntStringHelper (const IndexSequence<Index...> &) :
template<std::size_t... Index, typename Int = int, typename std::enable_if<IsNeg::value, Int>::type* = nullptr>
constexpr StaticIntStringHelper(const IndexSequence<Index...> &) :
raw{ '-', char('0' + abs(Value) / pow10(N - Index - 3) % 10)..., '\0' } {}
};
};