www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to read this signature? (writeTo in DIP9)

reply Graham Fawcett <fawcett uwindsor.ca> writes:
Hi folks,

I'm having trouble deciphering this function signature, which appears
in the DIP9 proposal:

void writeTo(scope delegate(in char[] data) sink, 
	     string format = null) const

// from http://prowiki.org/wiki4d/wiki.cgi?LanguageDevel/DIPs/DIP9

Particularly, how does "scope" modify the delegate, and what is the
meaning of the trailing "const"?

Thanks,
Graham
Nov 19 2010
parent reply bearophile <bearophileHUGS lycos.com> writes:
Graham Fawcett:

 void writeTo(scope delegate(in char[] data) sink, 
 	     string format = null) const
 
 // from http://prowiki.org/wiki4d/wiki.cgi?LanguageDevel/DIPs/DIP9
 
 Particularly, how does "scope" modify the delegate, and what is the
 meaning of the trailing "const"?
"scope" means that the sink delegate is not a true closure, its outer scope is never allocated on the heap. "const" member functions means that inside it the "this" is const, so writeTo() can't modify the class/struct attributes. Bye, bearophile
Nov 19 2010
parent Graham Fawcett <fawcett uwindsor.ca> writes:
On Fri, 19 Nov 2010 14:43:03 -0500, bearophile wrote:

 Graham Fawcett:
 
 void writeTo(scope delegate(in char[] data) sink,
 	     string format = null) const
 
 // from http://prowiki.org/wiki4d/wiki.cgi?LanguageDevel/DIPs/DIP9
 
 Particularly, how does "scope" modify the delegate, and what is the
 meaning of the trailing "const"?
"scope" means that the sink delegate is not a true closure, its outer scope is never allocated on the heap. "const" member functions means that inside it the "this" is const, so writeTo() can't modify the class/struct attributes.
Ah! Thanks very much, bearophile! Graham
Nov 19 2010