www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Cannot use the same template arguments on function as the ones on

reply "MrSmith" <mrsmith33 yandex.ru> writes:
Here I have templated struct that matches type with CborConfig 
tempate specialization

CborConfig will have more parameters in future and all of them 
will be accessed via alias members, so I've used variadic (T...) 
parameter whule matching.

-------
template CborConfig(_nonSerializedAttribute)
{
	struct CborConfig
	{
		alias nonSerializedAttribute = _nonSerializedAttribute;
	}
}

/// Default non-serialized attribute type
struct NonSerialized{}

/// This CborConfig instantiation will be used by default.
alias defaultCborConfig = CborConfig!(NonSerialized, 
NonSerialized);

struct AccepterT(Config : CborConfig!(T) = defaultCborConfig, 
T...)
{
	pragma(msg, T);
}

// template f379.accepter cannot deduce function from argument 
types !()()
void accepter(Config : CborConfig!(T) = defaultCborConfig, T...)()
{
	pragma(msg, T);
}
-------
^^^^^^^
http://dpaste.dzfl.pl/5f1d5d5d9e19

Instead I need to use template constraint which is less compact.
http://dpaste.dzfl.pl/571ae84d783e

Why such behavior happens?
Feb 11 2015
next sibling parent reply "anonymous" <anonymous example.com> writes:
On Wednesday, 11 February 2015 at 22:14:44 UTC, MrSmith wrote:
 http://dpaste.dzfl.pl/5f1d5d5d9e19

 Instead I need to use template constraint which is less compact.
 http://dpaste.dzfl.pl/571ae84d783e

 Why such behavior happens?
Seems to work when you add an empty template argument list to `accepter()`, making it `accepter!()()`: http://dpaste.dzfl.pl/2ec186453907 So, compiler bug, I guess? The error message says it tried "!()()", but explicit "!()()" actually works. And the empty template argument list should be optional anyway.
Feb 11 2015
parent reply "Kenji Hara" <k.hara.pg gmail.com> writes:
On Wednesday, 11 February 2015 at 22:24:53 UTC, anonymous wrote:
 On Wednesday, 11 February 2015 at 22:14:44 UTC, MrSmith wrote:
 http://dpaste.dzfl.pl/5f1d5d5d9e19

 Instead I need to use template constraint which is less 
 compact.
 http://dpaste.dzfl.pl/571ae84d783e

 Why such behavior happens?
Seems to work when you add an empty template argument list to `accepter()`, making it `accepter!()()`: http://dpaste.dzfl.pl/2ec186453907 So, compiler bug, I guess? The error message says it tried "!()()", but explicit "!()()" actually works. And the empty template argument list should be optional anyway.
It would be a compiler bug. As far as I know, accepter() and accepter!()() has no difference in IFTI. I filed the issue in bugzilla. https://issues.dlang.org/show_bug.cgi?id=14174 Kenji Hara
Feb 12 2015
parent "MrSmith" <mrsmith33 yandex.ru> writes:
Thank you!
Feb 12 2015
prev sibling parent reply "Stefan Koch" <uplink.coder googlemail.com> writes:
DMD cannot overload templated and non-templated functions
an empty template argument is needed
Feb 11 2015
parent reply Jonathan M Davis via Digitalmars-d-learn writes:
On Thursday, February 12, 2015 07:11:12 Stefan Koch via Digitalmars-d-learn
wrote:
 DMD cannot overload templated and non-templated functions
 an empty template argument is needed
That's not actually true anymore. However, you have to be really careful when you do it, because it pretty much always favors calling the non-templated overload when it can, so you need to be very sure that the right overloads are getting called with the various types. Ultimately, I think that it's just better to templatize all of the functions and then get the constraints right, but if the set of types that are supposed to use the templated overload aren't even vaguely related to the non-templated overload, then you're probably okay. However, I've found that stuff like constness and inheritance tends to make it so that the non-templated overload ends up being called when I want the templated one to be called. So, in the end, it just pays to test and make sure that the right overload gets called for the various types that are supposed to be used with them. - Jonathan M Davis
Feb 11 2015
parent "MrSmith" <mrsmith33 yandex.ru> writes:
Thanks, everyone.
Feb 12 2015