[webkit-dev] Using namespace std
Allan Sandfeld Jensen
kde at carewolf.com
Wed May 16 01:24:41 PDT 2012
On Tuesday 15 May 2012, Darin Adler wrote:
> On May 15, 2012, at 5:48 AM, Allan Sandfeld Jensen wrote:
> > To me it seems like an odd practice, so I would like to ask what original
> > rationale behind that style guideline is
>
> Adding a list of using declarations like "using std::min" to the top of
> each source file would give us another ongoing maintenance job. The list
> in each file would grow, we’d not remember to remove them when they are no
> longer needed, and so on.
>
> Adding "using namespace std" to the top of a source file deals with 99% of
> the issue without the trouble of maintaining another list at the top of
> each file.
>
That is reasonable. I am just generally wary of opening external namespaces,
since they can eventually expand and end up causing conflicts.
> When there is a conflict, there are typically many simple ways to resolve
> the conflict. Removing "using namespace std" entirely is not the only
> solution and we should avoid it if possible. I see in your patch in
> <https://bugs.webkit.org/show_bug.cgi?id=86465> that you have decided to
> remove it from many files, and before we do that I suggest we first
> investigate the other solutions.
>
> Unfortunately your patch does not say what the conflict is; I can’t make a
> helpful suggestion for an alternate solution without that information.
>
The conflict is between isinf, isnan and std::isinf and std::isnan, but the
conflict only exists in C++11 when constexpr versions are introduced.
Since the problem exists in both GCC 4.6 and 4.7, I see no alternative than
ensuring any files that uses isinf or isnan does not open the std namespace.
This is only around 10 files in total as you can see in my patch.
Also as I note in https://bugs.webkit.org/show_bug.cgi?id=59249, the only std
functions used in all these cases are std::min, std::max and
std::numeric_limits. If these three functions were declared using in
MathExtra.h then none of these files would need any using std declarations.
Best regards
`Allan
More information about the webkit-dev
mailing list