Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #11341 > unrolled thread

microsoft's pair(piecewise_construct_t,...) constructor

Started byMarc <marc.glisse@gmail.com>
First post2011-11-09 16:33 +0000
Last post2011-11-17 08:19 +0900
Articles 4 — 3 participants

Back to article view | Back to comp.lang.c++


Contents

  microsoft's pair(piecewise_construct_t,...) constructor Marc <marc.glisse@gmail.com> - 2011-11-09 16:33 +0000
    Re: microsoft's pair(piecewise_construct_t,...) constructor SG <s.gesemann@gmail.com> - 2011-11-14 05:50 -0800
      Re: microsoft's pair(piecewise_construct_t,...) constructor Marc <marc.glisse@gmail.com> - 2011-11-15 01:31 +0000
        Re: microsoft's pair(piecewise_construct_t,...) constructor Miles Bader <miles@gnu.org> - 2011-11-17 08:19 +0900

#11341 — microsoft's pair(piecewise_construct_t,...) constructor

FromMarc <marc.glisse@gmail.com>
Date2011-11-09 16:33 +0000
Subjectmicrosoft's pair(piecewise_construct_t,...) constructor
Message-ID<j9ea08$gsv$1@news-rocq.inria.fr>
Hello,

I was reading this page about the C++11 features in the next VC compiler:
http://blogs.msdn.com/b/vcblog/archive/2011/09/12/10209291.aspx

and was surprised by the following. Since they don't have variadic
templates, they mimic them for small enough numbers of arguments in
the standard library. And then they claim:
"pair's pair(piecewise_construct_t, tuple<Args1...>, tuple<Args2...>)
constructor had "interesting" effects.  This requires N^2 overloads
(if we support up to 10-tuples, that means 121 overloads, since empty
tuples count here too)."

I am surprised by this. As far as I know, the usual way to mimic
variadic tuple is:
template <class=void,class=void,/*repeat a few more times*/class=void>
struct tuple;

so tuple<int, double> is actually tuple<int, double, void, void...>

pair's constructor then looks like:
template<class A,class B>
template<class X0,class X1,...,class X10,class Y0,...,class Y10>
pair<A,B>::pair(piecewise_construct_t, tuple<X0,...,X10> x,
tuple<Y0,...,Y10> y):
first (construct_from_tuple<A>(x)),
second(construct_from_tuple<B>(y)){}

(plus possibly some std::move or other details)
Since we are only forwarding the tuple, we don't need to know how many
of the template parameters are void, so we only need a single maximal
overload. construct_from_tuple does need overloads, but only a linear
number of them.

Does someone understand their comment?

PS: I tried to comment on that blog entry, but a few days later my
comment hasn't appeared yet. Besides, a third of the comment form is
not visible with firefox. What do you expect from Microsoft?

[toc] | [next] | [standalone]


#11447

FromSG <s.gesemann@gmail.com>
Date2011-11-14 05:50 -0800
Message-ID<079caf44-6a9e-4f89-93dc-495541770d79@hh9g2000vbb.googlegroups.com>
In reply to#11341
On Nov 9, 5:33 pm, Marc <marc.gli...@gmail.com> wrote:
> Hello,
>
> I was reading this page about the C++11 features in the next VC compiler:http://blogs.msdn.com/b/vcblog/archive/2011/09/12/10209291.aspx
>
> and was surprised by the following. Since they don't have variadic
> templates, they mimic them for small enough numbers of arguments in
> the standard library. And then they claim:
> "pair's pair(piecewise_construct_t, tuple<Args1...>, tuple<Args2...>)
> constructor had "interesting" effects.  This requires N^2 overloads
> (if we support up to 10-tuples, that means 121 overloads, since empty
> tuples count here too)."
>
> I am surprised by this. As far as I know, the usual way to mimic
> variadic tuple is:
> template <class=void,class=void,/*repeat a few more times*/class=void>
> struct tuple;
>
> so tuple<int, double> is actually tuple<int, double, void, void...>
>
> pair's constructor then looks like:
> template<class A,class B>
> template<class X0,class X1,...,class X10,class Y0,...,class Y10>
> pair<A,B>::pair(piecewise_construct_t, tuple<X0,...,X10> x,
> tuple<Y0,...,Y10> y):
> first (construct_from_tuple<A>(x)),
> second(construct_from_tuple<B>(y)){}

But this is cheating. Here, you initialize the members 'first' and
'second' with a single argument (whatever construct_from_tuple
returns, presumable an A and a B object) whereas the standard demands
first and second to be directly constructed with the arguments of
types X0,X1,... and Y0,Y1,... respectivly.

SG

[toc] | [prev] | [next] | [standalone]


#11474

FromMarc <marc.glisse@gmail.com>
Date2011-11-15 01:31 +0000
Message-ID<j9sfck$vie$1@news-rocq.inria.fr>
In reply to#11447
SG  wrote:

> On Nov 9, 5:33 pm, Marc <marc.gli...@gmail.com> wrote:
>> pair's constructor then looks like:
>> template<class A,class B>
>> template<class X0,class X1,...,class X10,class Y0,...,class Y10>
>> pair<A,B>::pair(piecewise_construct_t, tuple<X0,...,X10> x,
>> tuple<Y0,...,Y10> y):
>> first (construct_from_tuple<A>(x)),
>> second(construct_from_tuple<B>(y)){}
> 
> But this is cheating. Here, you initialize the members 'first' and
> 'second' with a single argument (whatever construct_from_tuple
> returns, presumable an A and a B object) whereas the standard demands
> first and second to be directly constructed with the arguments of
> types X0,X1,... and Y0,Y1,... respectivly.

construct_from_tuple<A> directly initializes an A from x, and that A
happens to be "first". The issue would be that it relies on
copy-elision, and the compiler has a flag that disables copy-elision?

If you think this is an issue, would you mind filing a bug report
against libstdc++, which uses the same construction?

[toc] | [prev] | [next] | [standalone]


#11546

FromMiles Bader <miles@gnu.org>
Date2011-11-17 08:19 +0900
Message-ID<871ut7mza0.fsf@catnip.gol.com>
In reply to#11474
Marc <marc.glisse@gmail.com> writes:
> construct_from_tuple<A> directly initializes an A from x, and that A
> happens to be "first". The issue would be that it relies on
> copy-elision, and the compiler has a flag that disables copy-elision?
>
> If you think this is an issue, would you mind filing a bug report
> against libstdc++, which uses the same construction?

I can't comment on correctness here, but I'll note that libstdc++ can
get away with making more assumptions about the compiler's behavior
than (portable) user code, because libstdc++ is developed and
distributed along with the compiler...

-Miles

-- 
Patience, n. A minor form of despair, disguised as a virtue.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web