From 6752331581827886679
X-Google-Thread: f78e5,6f5c74c3d7959916
X-Google-NewGroupId: yes
X-Google-Attributes: gid7894ca11fe,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Received: by 10.68.232.42 with SMTP id tl10mr12779998pbc.7.1335657636676;
        Sat, 28 Apr 2012 17:00:36 -0700 (PDT)
MIME-Version: 1.0
Path: r9ni109992pbh.0!nntp.google.com!news1.google.com!goblin3!goblin1!goblin.stu.neva.ru!news.albasani.net!.POSTED!not-for-mail
From: "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>
Newsgroups: comp.std.c++
Subject: Re: make_shared and friends.
Date: Sat, 28 Apr 2012 17:00:32 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 37
Sender: std-cpp-request@vandevoorde.com
Approved: james.dennett@gmail.com
Message-ID: <jnepts$i5s$1@dont-email.me>
References: <5583145.28.1335476739188.JavaMail.geo-discussion-forums@ynnn35>
NNTP-Posting-Host: tmKkPRGO2cMrLNG5jY21G++OJ1otg1MODH9D4r9WD3g=
X-Trace: news.albasani.net c/A3W3wZmIfGEv6xDaBr0k/BZxt3/GjZI3e27wAbCwNYWsHLPjgpw66HjxXGPm+BT46tpj0/XfCnRQWX5ZjfBw==
X-Complaints-To: abuse@albasani.net
NNTP-Posting-Date: Sun, 29 Apr 2012 00:00:34 +0000 (UTC)
X-Mailer: Perl5 Mail::Internet v2.05
X-Submission-Address: std-cpp-submit@vandevoorde.com
Cancel-Lock: sha1:aNfn3wnhQKBttSy1aBgV/zvRr4E=
X-Original-Date: Fri, 27 Apr 2012 20:52:37 +0200
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

On 27.04.2012 20:12, Jason McKesson wrote:
>
> Does the C++11 specification allow you to say that the `make_shared`
> template is a friend, and thus guarantee that it can access the
> appropriate private constructors of a class? Yes, there is syntax that
> would make `make_shared` a friend. But does the spec *require* that
> the constructors are called directly from `make_shared` itself, since
> it cannot transfer friendship to any subsidiary object types?


I don't think so.

But as a practical matter make your destructor protected (or private),
instead of the constructors.

If the private constructors imply factory functions, then by switching
to making the destructor non-public for the general case you reduce
the number of construction/destruction support functions from M class
specific factory functions, where M is the average number of
constructors, to 1 common destroy function, which you can make a
friend. And if you have make_shared as a single common factory
function (note that this can be a bit unsafe since it or its wrapper
will then have access to /all/ the constructors), then by doing the
switch you introduce just 1 more function. No matter the number of
such classes you create.


Cheers & hth.,

- Alf


--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]


