Boost logo

Boost Users :

Subject: Re: [Boost-users] Metaprogramming Question
From: Nat Linden (nat_at_[hidden])
Date: 2012-02-09 14:49:15

On Thu, Feb 9, 2012 at 1:13 AM, John M. Dlugosz <mpbecey7gu_at_[hidden]>wrote:

I've not had much opportunity to do much template metaprogramming in my
> work, but I've kept up with my reading. So, might I get some advice on how
> to approach this problem?
> I'm thinking of an assert-like statement that follows the syntax of
> Boost.Format, thus avoiding the variadic argument list.
> But, I want to avoid doing any work except on failure. This means
> remembering the arguments including the following %arg stuff, and passing
> everything through to Boost.Format based on the condition.

This isn't metaprogramming -- or at least not new metaprogramming, rather
taking advantage of an existing library -- but my colleague came up with
what I consider a clever use of Boost.Lambda for a similar sort of problem.
We wanted a macro with usage of the form:

OURMACRO("some streaming expr " << value << ...);

that would stream arbitrary objects as in:

hidden_ostream_object << "some streaming expr " << value << ...;

His solution is like this:

template <typename FUNCTOR>
void ourmacro_f(const FUNCTOR& f)

#define OURMACRO(EXPRESSION) (ourmacro_f(boost::lambda::_1 << EXPRESSION))

> So, what approach should I use?
> Plain MPL and classic metaprogramming?
> Fusion?
> Phoenix?

In this case I guess Phoenix would be the way to go rather than

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at