Const is already there. It cannot deduce it

tcak via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun May 17 14:34:20 PDT 2015


[code]
void test(D)( const D data ) if( is(D: shared(char[]) ) ) { }

void main() {
	char[] text = new char[4];
	text[0] = 'a'; text[1] = 'b'; text[2] = 'c'; text[3] = 'd';
	
	auto t = cast( shared(const(char[])) )text[1..2];

	test( t );
}

[/code]

Error Message:
template main.test cannot deduce function from argument types 
!()(shared(const(char[])))

`t` is already shared(const(char[])), and `test` is expecting 
const shared(char[]). Aren't they already same?

--

Together with this question, I want to ask whether there is a way 
to check only being `shared`, only being `const`, or only being 
`char[]` of a template variable (D of `test` in this case)?


More information about the Digitalmars-d-learn mailing list