std::to_string und GCC 4.8.1
-
Hallo,
ich verwende Dev C++ von Orwell und wollte ein Programm mit GCC 4.8.1 schreiben, das auf std::to_string zugreift. Leider habe ich gelesen, dass der Compiler einen Bug bezüglich to_string hat.
Gibt es einen Patch dafür?MfG
keineAhnung2
-
Dieser Thread wurde von Moderator/in SeppJ aus dem Forum C++ (alle ISO-Standards) in das Forum Compiler- und IDE-Forum verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.
-
Ist das nicht ein MinGW Bug? MinGW hat leider einige Bugs, welche sonst bei GCC gefixt wurden, und früher hat auch ein Teil der Standard Library einfach gefehlt. Wenn es keinen neueren Release davon gibt, schaust du leider in die Röhre. Entweder selbst fixen oder einen anderen Compiler benutzen.
-
Ich persönlich verwende folgenden Fallback-Code:
template <typename Type, typename Enabled = void> struct max_size_string; template <typename Type> struct max_size_string<Type, typename std::enable_if<std::is_integral<Type>::value>::type> { static constexpr std::size_t value = 4 * sizeof(Type); }; template <typename Type> struct max_size_string<Type, typename std::enable_if<std::is_floating_point<Type>::value>::type> { static constexpr std::size_t value = std::numeric_limits<Type>::max_exponent10 + 20; }; template <typename Type> const char* format_option() noexcept; template <> inline const char* format_option<int>() noexcept { return "%d"; } template <> inline const char* format_option<long>() noexcept { return "%ld"; } template <> inline const char* format_option<long long>() noexcept { return "%lld"; } template <> inline const char* format_option<unsigned>() noexcept { return "%u"; } template <> inline const char* format_option<unsigned long>() noexcept { return "%lu"; } template <> inline const char* format_option<unsigned long long>() noexcept { return "%llu"; } template <> inline const char* format_option<float>() noexcept { return "%f"; } template <> inline const char* format_option<double>() noexcept { return "%f"; } template <> inline const char* format_option<long double>() noexcept { return "%Lf"; } template <typename Type> std::string to_string(const Type &t) { char buffer[max_size_string<Type>::value]; auto size = std::snprintf(buffer, max_size_string<Type>::value, format_option<Type>(), t); return std::string(buffer, size); }