Boost logo

Boost Users :

Subject: [Boost-users] [boost::format] operator % could use call_traits<..>::parameter_type
From: Luc Bourhis (luc_j_bourhis_at_[hidden])
Date: 2012-06-24 19:22:32


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)

If operator % took integral types by value instead, this would alleviate the problem. Hence the suggestion to use call_traits<T>::parameter_type instead of T const &.

Of course, the same could be said of many functions other than format::operator%

Best wishes,

Luc Bourhis


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