M
Marc
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>: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?
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>: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?