[c++0x] pair's variadic constructor (N2369, 20.2.3.4)
CoffeeBuzz
chris.fairles@gmail.com
Tue Aug 28 21:00:00 GMT 2007
Howard Hinnant-2 wrote:
>
> It stems from the recent "emplace" work in the associative containers.
>
Ah yes. I found the document. N2345
Howard Hinnant-2 wrote:
>
>> However, after implementing the full spec, I get some odd deduction
>> behavior
>> in all the ctor overloads. Take the following mock-pair class:
>>
>> template <typename T1, typename T2>
>> struct P {
>> P(){}
>> P(P && p) {}
>> P(T1 const& t1, T2 const& t2){}
>>
>> template <typename U1, typename U2>
>> P(P<U1,U2> const& p) {}
>>
>> template <typename U1, typename U2>
>> P(U1&& u1, U2&& u2) {}
>>
>> template <typename U1, typename U2>
>> P(P<U1,U2> && p) {}
>>
>> template <typename U, typename... Args>
>> P(U && u, Args&&... args) {cout << "why?"; }
>> };
>>
>> When I compile the following code:
>> P<int,int> p1(1,2);
>> P<int,int> p2(p1);
>>
>> It seems that the construction of p2 is not done by P(P<U1,U2>
>> const& p) or
>> P(P&& p) as I might have expected. Instead, P(U && u, Args&&...
>> args) is
>> chosen with U being type P<int, int>& and Args is no type (empty
>> pack).
>>
>> Now this is an issue because in the pair, this variadic ctor
>> forwards u to
>> "first" and args to "second" but first is type int, and not
>> P<int,int>& and
>> thus errors. So, how do you stop this behavior?
>
> I agree we have a problem here. I believe the answer is going to be
> along the lines of:
>
> template<class U, class Arg0, class... Args> pair(U&& x, Arg0&&
> arg0, Args&&... args)
> : first(std::forward<U>(x)), second(std::forward<Arg0>(arg0),
> std::forward<Args>(args)...)
>
This does indeed solve the pair construction issue and doesn't seem to
affect the tuple-pair interface (in my test cases anyway).
Thanks,
Chris
--
View this message in context: http://www.nabble.com/-c%2B%2B0x--pair%27s-variadic-constructor-%28N2369%2C-20.2.3.4%29-tf4337197.html#a12376060
Sent from the gcc - libstdc++ mailing list archive at Nabble.com.
More information about the Libstdc++
mailing list