Structs and Variadic Functions

Xinok xnknet at gmail.com
Tue Dec 19 22:02:10 PST 2006


The main use I saw for this feature was passing properties to a function. Take for
example, a file class:

class File{
	private struct FProp{
		string path; // Path to the file to open
		bool read, write; // Open file to read or write
		int cache; // File cache
		bool temp; // Temporary file?
		bool binary; // Open file in binary mode?
	}

	this(FProp prop ...); // Constructor
}


int main(){
	File ifile(path : "C:\\in.dat", read : true, cache : 4096);
	File ofile(path : "C:\\out.dat", write : true, cache : 0, temp : true);
}


You only set the properties you need, and in any order you want.



More information about the Digitalmars-d mailing list