www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Auto field member?

reply Hanh <hanh425 gmail.com> writes:
Hi,

Is there a way to declare a class field 'auto'? I have a problem 
when I try to 'promote' a variable to a field.

import std.csv;
import std.typecons;

class Test {
	this() {
		auto text = "Joe,Carpenter,300000\nFred,Blacksmith,400000\r\n";
     	        auto reader = csvReader!(Tuple!(string, string, 
int))(text); // how to make this a field?
     }
}

csvReader returns a private type so I can't specify the type 
explicitly.

Thanks,
--h
Mar 01 2016
parent Rikki Cattermole <alphaglosined gmail.com> writes:
On 02/03/16 3:50 PM, Hanh wrote:
 Hi,

 Is there a way to declare a class field 'auto'? I have a problem when I
 try to 'promote' a variable to a field.

 import std.csv;
 import std.typecons;

 class Test {
      this() {
          auto text = "Joe,Carpenter,300000\nFred,Blacksmith,400000\r\n";
                  auto reader = csvReader!(Tuple!(string, string,
 int))(text); // how to make this a field?
      }
 }

 csvReader returns a private type so I can't specify the type explicitly.

 Thanks,
 --h
You have two options. a) parse and store into your own data structure. b) use std.traits ReturnType to get the type to declare.
Mar 01 2016