Search code examples
c++c++11decltypereturn-type-deductiontrailing-return-type

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.


Solution

  • 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.