#include <iostream>
#include <algorithm>
#include <iterator>
#include <utility>
namespace hoge {
// intとdoubleを読み込むイテレータ
class my_iter
: public std::iterator< std::forward_iterator_tag, my_iter> {
public:
// Constructors
my_iter()
: stream_(0), eof_(true), values_(std::pair< int, double>()) {
// デフォルトはeofとする
}
explicit my_iter(std::istream *stream)
: stream_(stream), eof_(false), values_(std::pair< int, double>()) {
read();
}
// Copy
my_iter(my_iter const &other)
: stream_(other.stream_), eof_(other.eof_), values_(other.values_) {
}
my_iter& operator=(my_iter const &other) {
if(this != &other) {
my_iter(other);
std::swap(*this, other);
}
return *this;
}
// Move
my_iter(my_iter &&other)
: stream_(0), eof_(true), values_(std::pair< int, double>()) {
std::swap(stream_, other.stream_);
std::swap(eof_, other.eof_);
std::swap(values_, other.values_);
}
my_iter& operator=(my_iter &&other) {
if(this != &other)
std::swap(*this, other);
return *this;
}
// 前置
my_iter& operator++() {
read();
return *this;
}
// デリファレンス
std::pair< int, double>& operator*() {
return values_;
}
// 比較
friend bool operator==(my_iter const &lhs, my_iter const &rhs) {
return lhs.eof_ && rhs.eof_; // 両方がeofだったらイコール
}
friend bool operator!=(my_iter const &lhs, my_iter const &rhs) {
return !(lhs == rhs);
}
private:
// 読み込み
void read() {
if(!eof_)
if(!(*stream_).eof()) {
*stream_ >> values_.first;
if(!(*stream_).eof())
*stream_ >> values_.second;
else
eof_ = true;
} else
eof_ = true;
}
std::istream *stream_; // ストリーム
bool eof_; // eofに達したかどうか
std::pair< int, double> values_; // 読み込んだ値
};
} // namespace hoge
// ---- MAIN ---
using namespace std;
using namespace hoge;
int main() {
int i=0;
my_iter it(&cin);
my_iter it_end;
for_each(it, it_end,
[&i](pair< int, double> const &v) {
++i;
if(v.second < 0.0)
cout << "fail (line=" << i << ")" << endl;
else
cout << v.first << " " << v.second << endl;
}
);
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8aXRlcmF0b3I+CiNpbmNsdWR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