|
Boost Users : |
Subject: Re: [Boost-users] preprocessor metaprogramming question
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2010-06-20 20:38:41
> From: watanabesj_at_[hidden]
> 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.
_________________________________________________________________
MSN Dating: Find someone special. Start now.
http://go.microsoft.com/?linkid=9734384
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