point
is standalone.point
is standalone.It knows how to read itself from a stream, how to print itself into stream, and it handles that narrowing conversion on its own. Do note the use of aggregate initializer.
Ignoring commas and other formatting issues are delegated to stream. The old locale is restored, to behave as a good citizen and avoid surprising behaior when code gets modified.
Iterators are used extensively to reduce boilerplate and naked loops, although at some cost of being beginner friendly
It knows how to read itself from a stream, how to print itself into stream, and it handles that narrowing conversion on its own. Do note the use of aggregate initializer.
Ignoring commas and other formatting issues are delegated to stream. The old locale is restored, to behave as a good citizen and avoid surprising behaior when code gets modified.
Iterators are used extensively to reduce boilerplate and naked loops, although at some cost of being beginner friendly
point
is standalone.
It knows how to read itself from a stream, how to print itself into stream, and it handles that narrowing conversion on its own. Do note the use of aggregate initializer.
Ignoring commas and other formatting issues are delegated to stream. The old locale is restored, to behave as a good citizen and avoid surprising behaior when code gets modified.
Iterators are used extensively to reduce boilerplate and naked loops, although at some cost of being beginner friendly
point
is standalone.It knows how to read itself from a stream, how to print itself into stream, and it handles that narrowing conversion on its own. Do note the use of aggregate initializer.
Ignoring commas and other formatting issues are delegated to stream. The old locale is restored, to behave as a good citizen and avoid surprising behaior when code gets modified.
Iterators are used extensively to reduce boilerplate and naked loops, although at some cost of being beginner friendly
#include <iostream>
#include <cctype>
#include <vector>
#include <limits>
struct point {
int x;
int y;
double z;
};
std::istream& operator>>(std::istream& is, point& p) {
double x, y, z;
is >> x >> y >> z;
p = {static_cast<int>(x),
static_cast<int>(y),
z}; //explicit conversion, as implicit is not allowed
return is;
}
std::ostream& operator<<(std::ostream& os, const point& p) {
return os << p.x << ' ' << p.y << ' ' << p.z;
}
struct custom_classification : std::ctype<char> {
custom_classification() : ctype(make_table()) { }
private:
static mask* make_table() {
const mask* classic = classic_table();
static std::vector<mask> v(classic, classic + table_size);
v[','] |= space;
return &v[0];
}
};
std::vector<point> read_points(std::istream& is) {
auto old_locale = is.getloc();
is.imbue(std::locale(is.getloc(), new custom_classification));
is.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
auto points = std::vector(std::istream_iterator<point>(is), {});
is.imbue(old_locale);
return points;
}
int main() {
auto points = read_points(std::cin);
for (auto&& a_point: points) {
std::cout << a_point << '\n';
}
}
#include <iostream>
#include <cctype>
#include <vector>
#include <limits>
struct point {
int x;
int y;
double z;
};
std::istream& operator>>(std::istream& is, point& p) {
double x, y, z;
is >> x >> y >> z;
p = {static_cast<int>(x),
static_cast<int>(y),
z}; //explicit conversion, as implicit is not allowed
return is;
}
std::ostream& operator<<(std::ostream& os, const point& p) {
return os << p.x << ' ' << p.y << ' ' << p.z;
}
struct custom_classification : std::ctype<char> {
custom_classification() : ctype(make_table()) { }
private:
static mask* make_table() {
const mask* classic = classic_table();
static std::vector<mask> v(classic, classic + table_size);
v[','] |= space;
return &v[0];
}
};
std::vector<point> read_points(std::istream& is) {
auto old_locale = is.getloc();
is.imbue(std::locale(is.getloc(), new custom_classification));
is.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
auto points = std::vector(std::istream_iterator<point>(is), {});
is.imbue(old_locale);
return points;
}
int main() {
auto points = read_points(std::cin);
for (auto&& a_point: points) {
std::cout << a_point << '\n';
}
}
#include <iostream>
#include <cctype>
#include <vector>
#include <limits>
struct point {
int x;
int y;
double z;
};
std::istream& operator>>(std::istream& is, point& p) {
double x, y, z;
is >> x >> y >> z;
p = {static_cast<int>(x),
static_cast<int>(y),
z}; //explicit conversion, as implicit is not allowed
return is;
}
std::ostream& operator<<(std::ostream& os, const point& p) {
return os << p.x << ' ' << p.y << ' ' << p.z;
}
struct custom_classification : std::ctype<char> {
custom_classification() : ctype(make_table()) { }
private:
static mask* make_table() {
const mask* classic = classic_table();
static std::vector<mask> v(classic, classic + table_size);
v[','] |= space;
return &v[0];
}
};
std::vector<point> read_points(std::istream& is) {
auto old_locale = is.imbue(std::locale(is.getloc(), new custom_classification));
is.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
auto points = std::vector(std::istream_iterator<point>(is), {});
is.imbue(old_locale);
return points;
}
int main() {
auto points = read_points(std::cin);
for (auto&& a_point: points) {
std::cout << a_point << '\n';
}
}
#include <iostream>
#include <cctype>
#include <vector>
#include <limits>
struct point {
int x;
int y;
double z;
};
std::istream& operator>>(std::istream& is, point& p) {
double x, y, z;
is >> x >> y >> z;
p = {static_cast<int>(x),
static_cast<int>(y),
z}; //explicit conversion, as implicit is not allowed
return is;
}
std::ostream& operator<<(std::ostream& os, const point& p) {
return os << p.x << ' ' << p.y << ' ' << p.z;
}
struct custom_classification : std::ctype<char> {
custom_classification() : ctype(make_table()) { }
private:
static mask* make_table() {
const mask* classic = classic_table();
static std::vector<mask> v(classic, classic + table_size);
v[','] |= space;
return &v[0];
}
};
std::vector<point> read_points(std::istream& is) {
auto old_locale = is.getloc();
is.imbue(std::locale(is.getloc(), new custom_classification));
is.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
return auto points = std::vector(std::istream_iterator<point>(is), {});
is.imbue(old_locale);
return points;
}
int main() {
auto points = read_points(std::cin);
for (auto&& a_point: points) {
std::cout << a_point << '\n';
}
}
Demo on Wandbox Demo on Wandbox.
Ignoring commas and other formatting issues are delegated to stream. The old locale is restored, to behave as a good citizen and avoid surprising behaior when code gets modified.
Iterators are used extensively to reduce boilerplate and naked loops, although at some cost of being beginner friendly
#include <iostream>
#include <cctype>
#include <vector>
#include <limits>
struct point {
int x;
int y;
double z;
};
std::istream& operator>>(std::istream& is, point& p) {
double x, y, z;
is >> x >> y >> z;
p = {static_cast<int>(x),
static_cast<int>(y),
z}; //explicit conversion, as implicit is not allowed
return is;
}
std::ostream& operator<<(std::ostream& os, const point& p) {
return os << p.x << ' ' << p.y << ' ' << p.z;
}
struct custom_classification : std::ctype<char> {
custom_classification() : ctype(make_table()) { }
private:
static mask* make_table() {
const mask* classic = classic_table();
static std::vector<mask> v(classic, classic + table_size);
v[','] |= space;
return &v[0];
}
};
std::vector<point> read_points(std::istream& is) {
is.imbue(std::locale(is.getloc(), new custom_classification));
is.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
return std::vector(std::istream_iterator<point>(is), {});
}
int main() {
auto points = read_points(std::cin);
for (auto&& a_point: points) {
std::cout << a_point << '\n';
}
}
Ignoring commas and other formatting issues are delegated to stream
Iterators are used extensively to reduce boilerplate and naked loops, although at some cost of being beginner friendly
#include <iostream>
#include <cctype>
#include <vector>
#include <limits>
struct point {
int x;
int y;
double z;
};
std::istream& operator>>(std::istream& is, point& p) {
double x, y, z;
is >> x >> y >> z;
p = {static_cast<int>(x),
static_cast<int>(y),
z}; //explicit conversion, as implicit is not allowed
return is;
}
std::ostream& operator<<(std::ostream& os, const point& p) {
return os << p.x << ' ' << p.y << ' ' << p.z;
}
struct custom_classification : std::ctype<char> {
custom_classification() : ctype(make_table()) { }
private:
static mask* make_table() {
const mask* classic = classic_table();
static std::vector<mask> v(classic, classic + table_size);
v[','] |= space;
return &v[0];
}
};
std::vector<point> read_points(std::istream& is) {
auto old_locale = is.getloc();
is.imbue(std::locale(is.getloc(), new custom_classification));
is.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
auto points = std::vector(std::istream_iterator<point>(is), {});
is.imbue(old_locale);
return points;
}
int main() {
auto points = read_points(std::cin);
for (auto&& a_point: points) {
std::cout << a_point << '\n';
}
}
Ignoring commas and other formatting issues are delegated to stream. The old locale is restored, to behave as a good citizen and avoid surprising behaior when code gets modified.
Iterators are used extensively to reduce boilerplate and naked loops, although at some cost of being beginner friendly