If subscript operator is legal as non-member function in c++0x, could
we write?
template <typename...Types, int N>
auto operator[](tuple<Types...> && tup, int n = N) -> constexpr
decltype(get<N>(tup))
{
return get<N>(tup);
}
is this legal c++0x? Because if it is. We could write.
tuple<int, float, string> mytuple;
mytuple[2] = 12;
and expressions in array-like notation.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
german
|
5/9/2009 11:04:01 AM |
|
german diago wrote:
> If subscript operator is legal as non-member function in c++0x, could
> we write?
>
>
>
> template <typename...Types, int N>
> auto operator[](tuple<Types...> && tup, int n = N) -> constexpr
> decltype(get<N>(tup))
> {
> return get<N>(tup);
> }
>
>
> is this legal c++0x? Because if it is. We could write.
>
> tuple<int, float, string> mytuple;
>
> mytuple[2] = 12;
Sorry, but N cannot be deduced in this way.
Furthermore, we would get functions with weird signatures,
since default values are not part of it.
--
Dragan
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
Dragan
|
5/15/2009 5:43:39 AM
|
|