Boost logo

Boost Users :

Subject: Re: [Boost-users] Metaprogramming Question
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2012-02-09 01:21:59


On Thu, 9 Feb 2012, John M. Dlugosz 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.
>
> 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.

Would it be reasonable for your use case to have MY_FANCY_ASSERT be:

#define MY_FANCY_ASSERT(cond, str) \
   if (cond) {} else format(str) % __FILE__ % __LINE__

or similar? It would restrict where you could use it, but would be simple
and guarantee the properties you want.

-- Jeremiah Willcock


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