Skip to content

Commit

Permalink
add (temporary) support for missing from_chars
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaddyDC committed Jul 22, 2020
1 parent 76b6d1a commit 93cb0d5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/beatmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,18 @@ void osu::Beatmap_parser::parse_slider(const std::vector<std::string_view>& toke

std::transform(sub_tokens.cbegin() + 1, sub_tokens.cend(), std::back_inserter(slider.points), [](auto t)
{
Point point{};
const auto pos = std::from_chars(t.data(), t.data() + t.length(), point.x).ptr;
std::from_chars(pos + 1, t.data() + t.length(), point.y);
return point;
#if false
Point point{};
const auto pos = std::from_chars(t.data(), t.data() + t.length(), point.x).ptr;
std::from_chars(pos + 1, t.data() + t.length(), point.y);
return point;
#else // TODO: remove when from_chars is more widely supported
Point point{};
std::size_t pos = 0;
point.x = std::stof(&t.front(), &pos);
point.y = std::stof(&t.front() + pos + 1, nullptr);
return point;
#endif
});
beatmap_.sliders.push_back(slider);
}
Expand Down
13 changes: 13 additions & 0 deletions src/parse_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ void parse_value(std::string_view value_string, Type& value)
std::from_chars(value_string.data(), value_string.data() + value_string.length(), value);
}

// TODO: remove these when floating point from_chars is more widely supported
template<>
inline void parse_value<>(std::string_view value_string, float& value)
{
value = std::stof(std::string{ value_string });
}

template<>
inline void parse_value<>(std::string_view value_string, double& value)
{
value = std::stod(std::string{ value_string });
}

template<>
inline void parse_value<>(std::string_view value_string, bool& value)
{
Expand Down

0 comments on commit 93cb0d5

Please sign in to comment.