Boost logo

Boost Users :

Subject: [Boost-users] Metaprogramming Question
From: John M. Dlugosz (mpbecey7gu_at_[hidden])
Date: 2012-02-09 01:13:53


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.

     MY_FANCY_ASSERT (cond, "format string") % arg % arg;

works if the macro expands to an unnamed temporary, whose destructor does the interesting
work if the first argument is false.

     my_assert_formatter_type (cond, "cond", __FILE__, __LINE__, "format string")

This is easy to do, simply deriving from boost::formatter, I would think.

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.

So I'm thinking that template metaprogramming can let me collect all the arguments (any
number of them) into one object, efficiently at compile time.

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

and any concrete suggestions on how to proceed, or pointers to similar works?

Thanks,
—John


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