Fixing const arrays

Michel Fortin michel.fortin at michelf.com
Wed Dec 14 05:50:09 PST 2011


On 2011-12-14 13:27:57 +0000, "Regan Heath" <regan at netmail.co.nz> said:

> On Wed, 14 Dec 2011 02:36:43 -0000, Michel Fortin
> <michel.fortin at michelf.com> wrote:
> 
>> By "code patterns", you mean something like this?
>> 
>> 	struct Foo
>> 	{
>> 		int getBar();
>> 		void setBar(int);
>> 	}
>> 
>> 	void main()
>> 	{
>> 		Foo foo;
>> 		int a = foo.bar;  // calls getBar()
>> 		foo.bar = a;      // calls setBar(a)
>> 	}
> 
> Why not something similar to C# syntax...

I know the basics of the C# property syntax, but how do you take the 
address of the getter with it? And how do you define array-member 
properties like you can do with functions? And how do you disambiguate 
access those array members properties if two imported modules define a 
property with the same name for an array? It basically has the same 
undefined areas as the current syntax using @property.

With the code pattern syntax used above:

	&foo.bar; // take the address of the returned value (if returned by ref)
	&foo.getBar; // take the address of the getter
	&foo.setBar; // take the address of the setter


	void getFront(int[] array) { return array[0]; }

	int[] a;
	a.front; // array-member property made from a module-level function

	
	// disambiguated access if two imported modules
	// define the same array-member property
	std.range.getFront(a);
	other.mod.getFront(a);


-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



More information about the Digitalmars-d mailing list