25 Jun 2012 01:22
[boost::format] operator % could use call_traits<..>::parameter_type
Luc Bourhis <luc_j_bourhis <at> mac.com>
2012-06-24 23:22:32 GMT
2012-06-24 23:22:32 GMT
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

RSS Feed