www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - sameness

reply sclytrack <sclytrack fake.com> writes:
	---------------------------------------
	letters are different yet the same

	immutable(char) [] letter1;
	const(char) [] letter2;
	char [] letter3;

	void proc1( const(char) [] letter) {}

	---------------------------------------
	letters are different
	
	struct Container(T)
	{
		T letter;
	}

	Container!(const(char)) letter1;
	Container!(immutable(char)) letter2
	Container!(char) letter3;

	void proc2(Container!(const(char)) letter) {}

	---------------------------------------
Jan 20 2012
next sibling parent bearophile <bearophileHUGS lycos.com> writes:
sclytrack:

 	letters are different yet the same
 ...
 	letters are different
It's a Zen thing. Templates are very strict in the type you give them, while function arguments perform some silent type conversions. I think this will not change, because it's hard to design C++/D-style templates in a different way. In C++ happens something similar. Bye, bearophile
Jan 20 2012
prev sibling parent sclytrack <sclytrack hotmail.com> writes:
On 01/20/2012 01:18 PM, sclytrack wrote:
 ---------------------------------------
 letters are different yet the same

 immutable(char) [] letter1;
 const(char) [] letter2;
 char [] letter3;

 void proc1( const(char) [] letter) {}

 ---------------------------------------
 letters are different

 struct Container(T)
 {
 T letter;
 }

 Container!(const(char)) letter1;
 Container!(immutable(char)) letter2
 Container!(char) letter3;

 void proc2(Container!(const(char)) letter) {}

 ---------------------------------------
This means we can't create a Stride that would behave like a built in type. int stride a = new int stride(2,100); const int stride b = a; writeln(a.step); a[10]++; inout(int) hello(inout(int) stride a, inout(int) stride b) inout { } I've also noticed something. There is a lot of casting in the inout. 5 degrees Celsius. These modern computers barely heat up the room.
Feb 02 2012