Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > microsoft's pair(piecewise_construct_t,...) constructor

Reply
Thread Tools

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

 
 
Marc
Guest
Posts: n/a
 
      11-09-2011
Hello,

I was reading this page about the C++11 features in the next VC compiler:
http://blogs.msdn.com/b/vcblog/archi.../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>:air(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?
 
Reply With Quote
 
 
 
 
SG
Guest
Posts: n/a
 
      11-14-2011
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/archi.../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>:air(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
 
Reply With Quote
 
 
 
 
Marc
Guest
Posts: n/a
 
      11-15-2011
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>:air(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?
 
Reply With Quote
 
Miles Bader
Guest
Posts: n/a
 
      11-16-2011
Marc <> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A constructor calling another constructor (default constructor)? Generic Usenet Account C++ 10 11-28-2007 04:12 AM
Copy constructor hides default constructor Aire C++ 3 01-25-2004 05:47 PM
java like constructor calling constructor lallous C++ 5 01-23-2004 11:52 PM
calling a constructor within a constructor Brett Irving C++ 3 06-29-2003 10:43 AM
why it's not possible calling constructor from constructor? Giulio C++ 9 06-25-2003 03:56 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57