> From: watanabesj@gmail.com
> Nathan Ridge wrote:
> > Here's a question for the preprocessor metaprogramming experts out there.
> >
> > I have some classes that need to have write() methods that look like this:
> >
> > template <typename output>
> > bool write(output& out) const
> > {
> > return utils::write(out, member_1) &&
> > utils::write(out, member_2) &&
> > ...
> > utils::write(out, member_n);
> >
> > }
> >
> > where member_1, member_2, ..., member_n are the member variables of the class.
> >
>
> #include <boost/preprocessor/seq/for_each.hpp>
>
> #define WRITE(r, data, member) && utils::write(out, member)
>
> #define MEMBERS(members) \
> template<typename output> \
> bool write(output& out) const \
> { \
> return true \
> BOOST_PP_SEQ_FOR_EACH(WRITE, ~, members); \
> }
>
> MEMBERS((a)(b)(c))

Cool!
 
I don't suppose there's any way to have the syntax be MEMBERS(a, b, c)?
 
Thanks,
Nate.


Enter for a chance to get your town photo on Bing.ca! Submit a Photo Now!