N2369 editorial: Needless redundant effect description in [util.smartptr.shared.create]

N2369 editorial: Needless redundant effect description in [util.smartptr.shared.create]

Post by Daniel Krl » Sat, 25 Aug 2007 01:57:51


The newly proposed make_shared and allocate_shared function templates
have a redundant effects clause in [util.smartptr.shared.create]/p.2:

"Effects: Allocates memory suitable for an object of type T and
constructs
an object in that memory via the placement new expression new (pv) T()
or
new (pv) T(std::forward<Args>(args)...).[..]"

According to variadic template syntax emptypack expansions and empty
parameter packs are feasible such that the first mentioned expression
is
already described by the second one.

Proposed resolution:

Replace above wording in [util.smartptr.shared.create]/p.2 by:

"Effects: Allocates memory suitable for an object of type T and
constructs
an object in that memory via the placement new (pv)
T(std::forward<Args>(args)...).[..]"

Greetings from Bremen,

Daniel Krler


---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.yqcomputer.com/ ]
 
 
 

N2369 editorial: Needless redundant effect description in [util.smartptr.shared.create]

Post by pete » Sat, 25 Aug 2007 07:22:02

On 2007-08-23 12:57:51 -0400, Daniel Krler
< XXXX@XXXXX.COM > said:


That was my reaction when I merged the paper into the working draft.
Thanks for reminding me. (You can send editorial fixes to
XXXX@XXXXX.COM )

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)


---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.yqcomputer.com/ ]

 
 
 

N2369 editorial: Needless redundant effect description in [util.smartptr.shared.create]

Post by Peter Dimo » Thu, 30 Aug 2007 00:55:23

On Aug 24, 1:57 am, Daniel Krler < XXXX@XXXXX.COM >


Correct in principle. The motivation behind the redundancy was that
the reference variadic template implementation expanded 'new T(a...)'
into 'new T' when a was empty. This matters when T is a POD. We've
since discussed this issue and the correct expansion was clarified to
indeed be 'new T()'.

Nevertheless, I won't be surprised if some compilers get this wrong at
first, and when one needs to be able to convince a compiler/stdlib
vendor that make_shared<int>() should initialize the int to 0, having
explicit wording in the standard helps.


---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.yqcomputer.com/ ]
 
 
 

N2369 editorial: Needless redundant effect description in [util.smartptr.shared.create]

Post by Daniel Krl » Thu, 30 Aug 2007 19:08:41


I understand the noble reasons for the current writing, but I have
still
two reasons why I think that the current text should be changed:

1) IMO the current writing of the criticized paragraph is more
ambigious
than my corrected version. Isn't there at least a trailing ",
respectively"
missing (if my foreigner english takes me right...) to make clear that
only *one* of those cases apply?

2) Your basic argument holds, but I strongly think that exactly this
paragraph is the wrong place to clarify this issue. Please note that
we could argue for similar reasons that the description of
[allocator.members]/13 should have this important note, the
current text is simply given by:

template <class... Args> void construct(pointer p, Args&&... args);
Effects: ::new((void *)p) T(std::forward<Args>(args)...)

A call to std::allocator::construct with only a single argument *will*
invoke the above template overload of construct.
I have to possible locations in my mind where a proper
implementation-relevant note could be added:

a) [expr.new]/16, second (or third?) bullet: Add a footnote which says
something
along the lines of: "An empty parameter expansion is equivalent to the
form ()"

b) [dcl.init]/8: As part of the already given note just after the
sentence
starting with "The form () is permitted[..]" add one further sentence
along the
lines of "An empty parameter expansion is equivalent to the form ()".

What do you think?

Greetings from Bremen,

Daniel






---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.yqcomputer.com/ ]