🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Tangent: Generic Method Bodies, Part 2

Published July 08, 2009
Advertisement
Yet more time yesterday, so more work into generic methods. On the slate was type parameters, using generic references as the return type and resending the generic to another generic. The example code is fairly simple today; a in-source re-creation of the C# default keyword.

Remember that Exists is the super-type of everything and that Any is the super-type of everything but void. And local variables are default initialized out of the box.

public static    default => T{	local T rtn;	return(rtn);}public static    factory => T{	return(default);}public static    main()=>void{	default<void>;	print default<int>;	print default<decimal>;	print default;	print factory<int>;	//factory;	// error as expected.}
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement