[Cpp]
# Include <vector>
# Include <algorithm>
Class Seat
{
Public:
Seat (int no): no _ (no ){}
Int no _;
};
Class Table
{
Static const std: size_t BEGIN_SEAT = 1;
Static const std: size_t INVALID_SEAT = 0;
Static const std: size_t END_SEAT = 9;
Public:
Table ()
{
Seats _. push_back (new Seat (1 ));
Seats _. push_back (new Seat (2 ));
Seats _. push_back (new Seat (3 ));
Seats _. push_back (new Seat (4 ));
Seats _. push_back (new Seat (5 ));
Seats _. push_back (new Seat (6 ));
Seats _. push_back (new Seat (7 ));
Seats _. push_back (new Seat (8 ));
Seats _. push_back (new Seat (9 ));
}
Std: vector <Seat *> seats _;
Seat * get (const int seat)
{
Return seats _. at (seat-1 );
}
Public:
Class Iterator
{
Friend class CycleIterator;
Public:
Typedef size_t size_type;
Typedef ptrdiff_t difference_type;
Typedef std: forward_iterator_tag iterator_category;
Typedef Seat * value_type;
Typedef Seat ** pointer;
Typedef Seat * & reference;
Iterator (Table * table, const int position): table _ (table), position _ (position ){}
Iterator (const Iterator & it): table _ (it. table _), position _ (it. position _){}
Iterator operator ++ ()
{
For (++ position _; position _ <= Table: END_SEAT; ++ position _)
{
// If (table _-> get (position _)-> visible _ = true)
{
Return Iterator (table _, position _);
}
}
Position _ = Table: INVALID_SEAT;
Return Iterator (table _, Table: INVALID_SEAT );
}
Seat * operator-> ()
{
Return table _-> get (position _);
}
Seat * operator *()
{
Return table _-> get (position _);
}
Bool operator = (const Iterator & it) const
{
Return position _ = it. position _;
}
Bool operator! = (Const Iterator & it) const
{
Return position _! = It. position _;
}
Private:
Table * table _;
Int position _;
};
Public:
Iterator begin ()
{
Return Iterator (this, BEGIN_SEAT );
}
Iterator end ()
{
Return Iterator (this, INVALID_SEAT );
}
};
Bool FindNullSeat (Seat * seat)
{
Return seat-> no _ = 3;
}
Int main (int, char **)
{
Table table;
Table: Iterator seat = std: find_if (table. begin (), table. end (), FindNullSeat );
Return 0;
}
# Include <vector>
# Include <algorithm>
Class Seat
{
Public:
Seat (int no): no _ (no ){}
Int no _;
};
Class Table
{
Static const std: size_t BEGIN_SEAT = 1;
Static const std: size_t INVALID_SEAT = 0;
Static const std: size_t END_SEAT = 9;
Public:
Table ()
{
Seats _. push_back (new Seat (1 ));
Seats _. push_back (new Seat (2 ));
Seats _. push_back (new Seat (3 ));
Seats _. push_back (new Seat (4 ));
Seats _. push_back (new Seat (5 ));
Seats _. push_back (new Seat (6 ));
Seats _. push_back (new Seat (7 ));
Seats _. push_back (new Seat (8 ));
Seats _. push_back (new Seat (9 ));
}
Std: vector <Seat *> seats _;
Seat * get (const int seat)
{
Return seats _. at (seat-1 );
}
Public:
Class Iterator
{
Friend class CycleIterator;
Public:
Typedef size_t size_type;
Typedef ptrdiff_t difference_type;
Typedef std: forward_iterator_tag iterator_category;
Typedef Seat * value_type;
Typedef Seat ** pointer;
Typedef Seat * & reference;
Iterator (Table * table, const int position): table _ (table), position _ (position ){}
Iterator (const Iterator & it): table _ (it. table _), position _ (it. position _){}
Iterator operator ++ ()
{
For (++ position _; position _ <= Table: END_SEAT; ++ position _)
{
// If (table _-> get (position _)-> visible _ = true)
{
Return Iterator (table _, position _);
}
}
Position _ = Table: INVALID_SEAT;
Return Iterator (table _, Table: INVALID_SEAT );
}
Seat * operator-> ()
{
Return table _-> get (position _);
}
Seat * operator *()
{
Return table _-> get (position _);
}
Bool operator = (const Iterator & it) const
{
Return position _ = it. position _;
}
Bool operator! = (Const Iterator & it) const
{
Return position _! = It. position _;
}
Private:
Table * table _;
Int position _;
};
Public:
Iterator begin ()
{
Return Iterator (this, BEGIN_SEAT );
}
Iterator end ()
{
Return Iterator (this, INVALID_SEAT );
}
};
Bool FindNullSeat (Seat * seat)
{
Return seat-> no _ = 3;
}
Int main (int, char **)
{
Table table;
Table: Iterator seat = std: find_if (table. begin (), table. end (), FindNullSeat );
Return 0;
}