2012/6/25 Luc Bourhis <luc_j_bourhis@mac.com>
Hi,

consider a library featuring code like

template <..., unsigned Rank, ...> struct Foo { ... static unsigned const rank = Rank; .... };

as well as

boost::format(...) % Foo::rank

Such code will link if and only if a definition for Foo::rank is provided because the interface of operator % is

template <class T>
operator%(const T& x)

This is not possible in the library, as I do not know which values of Rank will be used by client code. Thus the only possibility is a hat trick like

boost::format(...) % (Foo::rank+0)

Hi,

For problems like this I use a trick a bit simpler:
boost::format(...) % +Foo::rank

Notice, that if foo looks uses some char type instead of int, like this:
typedef int8_t-or-char MyInt;
template <..., MyInt Rank, ...> struct Foo { ... static MyInt const rank = Rank; .... };
then both our above tricks change the behavior of format by promoting Rank to int, which is treated totally different than char. In my case the "char" behavior was unexpected, and the trick fixed that as well ;-)

My 0.02 cents.
Regards
Kris