opDispatch is grand!

so so at so.do
Sat Apr 10 15:50:44 PDT 2010


Because i made a mistake!

struct vector(T, uint N) {
	auto opDispatch(string s) const {
		static if(N>0 && ("x"==s || "r"==s)) return v_[0];
		static if(N>1 && ("y"==s || "g"==s)) return v_[1];
		static if(N>2 && ("z"==s || "b"==s)) return v_[2];
		static if(N>3 && ("w"==s || "a"==s)) return v_[3];
		static assert("boom!");
	}
private:
	T[N] v_;
}

Better...

On Sun, 11 Apr 2010 02:49:14 +0400, so <so at so.do> wrote:

>
> struct vector(T, uint N) {
> 	auto opDispatch(string s) const {
> 		static if(N>0 && ("x"==s || "r"==s)) return v_[0];
> 		static if(N>1 && ("y"==s || "g"==s)) return v_[0];
> 		static if(N>2 && ("z"==s || "b"==s)) return v_[0];
> 		static if(N>3 && ("w"==s || "a"==s)) return v_[0];
> 		static assert("boom!");
> 	}
> private:
> 	T[N] v_;
> }
>
> No unions, clean and all!
> Then why do we need properties?
>
>>>>
>
> When i am sick, i try distract myself, this is one of those times, so  
> just ignore me if it doesn't make sense :)
> Thanks!
>


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/



More information about the Digitalmars-d mailing list