2016-01
This commit is contained in:
@@ -66,6 +66,15 @@ auto operator-=(Coord &, Coord) -> Coord &;
|
||||
/// Write a coordinate to a string "(x,y)"
|
||||
auto operator<<(std::ostream &, Coord) -> std::ostream &;
|
||||
|
||||
/// Scale a coordinate
|
||||
auto operator*(std::int64_t, Coord) -> Coord;
|
||||
|
||||
/// Scale a coordinate
|
||||
auto operator*(Coord, std::int64_t) -> Coord;
|
||||
|
||||
/// Scale a coordinate
|
||||
auto operator*=(Coord &, std::int64_t) -> Coord &;
|
||||
|
||||
} // namespace
|
||||
|
||||
template<>
|
||||
|
@@ -30,6 +30,22 @@ auto ParseGrammar(G const& grammar, std::istream & in) -> typename G::start_type
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename G>
|
||||
auto ParseGrammar_(G const& grammar, std::istream & in) -> typename G::start_type::attr_type
|
||||
{
|
||||
namespace qi = boost::spirit::qi;
|
||||
auto result = typename G::start_type::attr_type {};
|
||||
auto const content = std::string{std::istreambuf_iterator{in}, {}};
|
||||
auto b = content.begin(); // updated on successful parse
|
||||
auto const e = content.end();
|
||||
|
||||
if (!qi::phrase_parse(b, e, grammar, qi::ascii::space, result) || b != e) {
|
||||
throw std::runtime_error{"Bad input file: " + content};
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@@ -95,6 +95,22 @@ auto operator-=(Coord & a, Coord b) -> Coord & {
|
||||
return a;
|
||||
}
|
||||
|
||||
auto operator*(Coord a, std::int64_t b) -> Coord {
|
||||
return a *= b;
|
||||
}
|
||||
|
||||
auto operator*(std::int64_t a, Coord b) -> Coord {
|
||||
b.x *= a;
|
||||
b.y *= a;
|
||||
return b;
|
||||
}
|
||||
|
||||
auto operator*=(Coord & a, std::int64_t b) -> Coord & {
|
||||
a.x *= b;
|
||||
a.y *= b;
|
||||
return a;
|
||||
}
|
||||
|
||||
auto operator<<(std::ostream & out, Coord c) -> std::ostream & {
|
||||
return out << "(" << c.x << "," << c.y << ")";
|
||||
}
|
||||
|
Reference in New Issue
Block a user