Unable to anchor a local variable type from a TUPLE.item_n
[email protected] (Alexander Rios) Fri, 05 Aug 2005 20:15:24 -0400
| Newsgroups | gmane.comp.lang.eiffel.smalleiffel |
|---|---|
| Message-ID | <[email protected]> |
The following code fails to compile:
class TESTER
creation {ANY}
execute
feature {NONE}
t: TUPLE[INTEGER,REAL_64,STRING];
execute is
local
x: like t.item_2
do
t := [ {INTEGER 1},2.0,"three"]
x := t.item_2
print(
"tuple.count: " + t.count.out + "%N" +
"item_1: " + t.item_1.out + "%N" +
"item_2: " + t.item_2.out + "%N" +
"item_3: " + t.item_3.out + "%N"
)
end
end
The following code succeeds to compile:
class TESTER
creation {ANY}
execute
feature {NONE}
r: REAL_64
t: TUPLE[INTEGER,like r,STRING];
execute is
local
x: like r
do
t := [ {INTEGER 1},2.0,"three"]
x := t.item_2
print(
"tuple.count: " + t.count.out + "%N" +
"item_1: " + t.item_1.out + "%N" +
"item_2: " + t.item_2.out + "%N" +
"item_3: " + t.item_3.out + "%N"
)
end
end
Since the second source compiles and runs fine.
I would expect the first to compile and run too.
Did we miss something?
BTW
The Boost C++ tuple class library can do this.
And so can the tuple<> class that has been proposed
for the next ISO C++ standard.
I mean a local variable can be declared whose
type is the same as a tuple's 2nd item's type.
C++ tuple indexing is zero based.
Although not too pretty in my eyes,
the C++ code would look like:
#include<iostream>
#include<string>
#include<tuple>
using namespace std;
int main(int count,char** arguments) {
tuple<int,double,string> t(1,2.0,"three");
tuple_element<1,tuple<int,double,string>::type x = get<1>(t) // HERE IT IS.
cout
<< "tuple.size=" << tuple_size< tuple<int,double,string> >::value << '\n'
<< "t[0]= " << get<0>(t) << '\n'
<< "t[1]= " << get<1>(t) << '\n'
<< "t[2]= " << get<2>(t) << '\n';
return 0;
}
__________________________________________________________________
Switch to Netscape Internet Service.
As low as $9.95 a month -- Sign up today at http://isp.netscape.com/register
Netscape. Just the Net You Need.
New! Netscape Toolbar for Internet Explorer
Search from anywhere on the Web and block those annoying pop-ups.
Download now at http://channels.netscape.com/ns/search/install.jsp