C++11 Avoiding Redundant Return Type in specific Situation

Ok, thanks everyone who has looked at this. I've recreated the exact scenario for easy viewing at the link below, so I'll just comment out the original text I had as it wasn't clear. http://cpp.sh/5lp4l

In the comment section I show calling make_some(32, std::string{"hi"}) without specifying the Data type declaration for the call. I realize this seems insane and way above my expected use case, automatically inferring the composite type (inferring I wanted Data, based on the int/string) based on the arguments wasn't necessary, or a good idea.

Answers


The compiler is right. There's just no relation given between T and Args. Hence, it cannot determine what QueryResult<T> means.

What you apparently expect is that the return type of somefn forces T to be int, int. That's obviously not possible for two reasons: T denotes a single type, and there's just no mechanism by which the return statement somehow affects the template instantiation of make_some.


Have you tried using auto as type declaration?

Also decltype (variable_here) variable_to_inherit_type; sets the type of the second variable to that of the first variable. You might be able to first set the type the same as the incoming variable using this.

I am not sure if this will work in your case but let me know if it helps!


Need Your Help

How to retrieve the cluster centroids in sic-kit learn's K-means?

python scikit-learn k-means

I'm using this simple script to cluster data using sci-kit learn