Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost::format] operator % could use call_traits<..>::parameter_type
From: Luc Bourhis (luc_j_bourhis_at_[hidden])
Date: 2012-06-25 06:42:58


Hi,

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

Neat! I had not thought of that.

However, and I did not explain it in my original post, what I actually did was to define a function with a long winded name like
alleviate_static_integral_const_member_definition to hide the trick and make it plain obvious there is a potential problem there.
Call me paranoid but I am always afraid of cute notations in a large project on the long term.

> 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 ;-)

Good point. Not a problem in my case but I could change my function to

template<class T> typename boost::enable_if<boost::is_integral<T>, T >::type
alleviate_static_integral_const_member_definition(T x) {
        return x;
}

for safety.


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