|
Boost Users : |
From: Graham Reitz (graham.cpp_at_[hidden])
Date: 2007-04-15 20:40:37
I thought that for_each() goes while (it != end). How does for_each()
'know' what end is here? It doesn't seem to be initialized to anything.
Thanks much,
Graham
class regex_callback
{
int m_sum;
public:
regex_callback() : m_sum(0) {}
template <typename T> void operator()(const T& what)
{ m_sum += boost::lexical_cast<int>(what[1].str().c_str()); }
int sum() const { return m_sum; }
};
int main()
{
boost::regex("(\\d+),?");
string s = "1,1,2,3,5,8,13,21";
boost::sregex_iterator it(s.begin(), s.end(), reg);
// Is end initialized to anything here?
boost::sregex_iterator end;
regex_callback c;
// How is end valid here?
int sum = for_each(it, end, c).sum();
return 0;
}
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net