Skip to content

Commit

Permalink
Fix compatibility with Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Ribeiro committed Jan 29, 2019
1 parent d6559fe commit 7c5669f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions library/cpp/base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,17 @@ template<typename T> struct traits
}
if (temp.empty()) return false;

#if defined(_WIN32) || defined(_WIN64)
static _locale_t loc = _create_locale(LC_NUMERIC_MASK | LC_MONETARY_MASK, "C");
if (loc == 0) return false;
value = (T) _strtod_l(temp.c_str(), NULL, loc);
#else
static locale_t loc = newlocale(LC_NUMERIC_MASK | LC_MONETARY_MASK, "C", 0);
if (loc == 0) return false;
uselocale(loc);
value = (T) strtod(temp.c_str(), NULL);
uselocale(LC_GLOBAL_LOCALE);
#endif
return true;
}
static void swap( T &a, T &b ) { T temp = a; a = b; b = temp; }
Expand Down

0 comments on commit 7c5669f

Please sign in to comment.