On Tue, 12 Jul 2022 at 15:06, Pedro Alves <pe...@palves.net> wrote:
>
> On 2022-07-12 2:45 p.m., Jonathan Wakely wrote:
> > On Tue, 12 Jul 2022 at 14:24, Pedro Alves wrote:
> >>
> >> On 2022-07-12 1:25 a.m., David Malcolm via Gcc-patches wrote:
> >>
> >>> I tried adding it to gcc/system.h, but anything that uses it needs to
> >>> have std::unique_ptr declared, which meant forcibly including <memory>
> >>> from gcc/system.h
> >>
> >> Did you consider making gcc/system.h include gcc/make-unique.h itself
> >> if INCLUDE_MEMORY is defined?  Something like:
> >>
> >>  #ifdef INCLUDE_MEMORY
> >>  # include <memory>
> >> + #include "make-unique.h"
> >>  #endif
> >>
> >> This is because std::make_unique is defined in <memory> in C++14.  This 
> >> would
> >> mean fewer changes once GCC requires C++14 (or later) and this new header 
> >> is eliminated.
> >
> > That's a good idea.
> >
> >>> (in the root namespace, rather than std::, which saves a bit more typing).
> >>
> >> It's less typing now, but it will be more churn once GCC requires C++14 
> >> (or later), at
> >> which point you'll naturally want to get rid of the custom make_unique.  
> >> More churn
> >> since make_unique -> std::make_unique may require re-indentation of 
> >> arguments, etc.
> >> For that reason, I would suggest instead to put the function (and any 
> >> other straight
> >> standard library backport) in a 3-letter namespace already, like, 
> >> gcc::make_unique
> >> or gnu::make_unique.  That way, when the time comes that GCC requires 
> >> C++14,
> >> the patch to replace gcc::make_unique won't have to worry about 
> >> reindenting code,
> >> it'll just replace gcc -> std.
> >
> > Or (when the time comes) don't change gcc->std and do:
> >
> > namespace gcc {
> >   using std::make_unique;
> > }
>
> It will seem like a pointless indirection then, IMO.
>
> >
> > or just leave it in the global namespace as in your current patch, and
> > at a later date add a using-declaration to the global namespace:
> >
> > using std::make_unique;
> >
>
> That's not very idiomatic, though.  Let me turn this into a reverse question:
>
> If GCC required C++14 today, would you be doing the above, either importing 
> make_unique
> to the global namespace, or into namespace gcc?   I think it's safe to say 
> that, no,
> nobody would be doing that.

Erm, I might well do exactly that, for either case.

I don't see a problem with 'using std::make_unique;' into the global
namespace in GCC code. It's not a library header being included by
arbitrary code, it's a single application that isn't going to have
conflicts for some other ::make_unique defined in GCC (because the
::make_unique that is being proposed today would be removed once
C++14's std::make_unique can be used).


>  So once GCC requires C++14, why would you want to preserve
> once-backported symbols in a namespace other than std, when you no longer 
> have a reason to?
> It will just be another unnecessary thing that newcomers at that future time 
> will have
> to learn.

I also don't see a problem with importing std::make_unique into
namespace gcc for local use alongside other things in namespace gcc. I
do consider that idiomatic. It says "the make_unique for gcc code is
std::make_unique". It means you only need a 'using namespace gcc;' at
the top of a source file and you get access to everything in namespace
gcc, even if it is something like std::make_unique that was originally
defined in a different namespace.

Reply via email to