Boost logo

Boost Users :

Subject: Re: [Boost-users] conflicting intmax_t definitions - Boost 1.53 and gcc 4.8 incompatibility?
From: John M. Dlugosz (ngnr63q02_at_[hidden])
Date: 2014-01-26 20:51:21


On 1/21/2014 9:27 AM, Leon Mlakar wrote:
> On 21/01/14 16:20, John M. Dlugosz wrote:
>> On 1/20/2014 6:32 AM, Nate Finch wrote:
> Or alternatively avoid using "using" and use fully qualified names (e.g. boost::intmax_t)
> - there's nothing wrong with this, either.
>

Actually, there are cases where that's not right, when writing templates. In particular,
swap(x,y) where x and y are of type T. You need to write it unqualified to have it find
swap via argument-dependent lookup, but when T is int it needs to find std::swap. The
idiom (as far as I know) is to declare `using std::swap;` in the function body.

FWIW, I often like having common things ready for unqualified use in my CPP files, such as
`string` and `make_shared`. I find it easier to read, and it keeps the lines shorter so
the real expression fits in one single-gaze clump of reading text.

For something like boost::intmax_t where the code wants to emphasize which one is being
called, qualifying helps with future maintenance. Like most classes use std::shared_ptr
but others (e.g. asio) use boost::shared_ptr, so it's awkward when writing the functions
that use both of them.

In headers, scope-pollution is prohibited (I mean by policy, not by the language). For
most coders that means the rule is equivalent to "don't use `using` in headers".


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