Now, I want to use strf::range<const char*>(some_char_ptr, some_char_ptr + some_length) in my code. But if I do so, I get the following error (w

How can I prevent C++ guessing a second template argument?

submited by
Style Pass
2021-06-23 14:00:04

Now, I want to use strf::range<const char*>(some_char_ptr, some_char_ptr + some_length) in my code. But if I do so, I get the following error (with CUDA 10.1's NVCC):

to ensure Range is not a pointer); but I can't make that change right now. Instead, I want to somehow indicate to the compiler that I really really mean to only have one template argument, not one specified and another one deduced.

Would appreciate answers for C++11 and C++14; C++17 answers involving deduction guides are less relevant but if you have one, please post it (for future NVCC versions...)

range1_ptr<T>(...) can always be used to explicitly call the template taking one template argument, but does not do any deduction from the arguments. range1 replicates the deduction from the original strf::range template.

This works, because [temp.deduct.funcaddr]/1 says that template argument deduction when taking the address of a function without target type of the conversion is done on each candidate function template as if the parameter and argument lists of a hypothetical call were empty. So the second template argument cannot be deduced for the second overload with two template parameters. The only candidate left is the first overload, which will be chosen as the target of the function pointer.

Leave a Comment