--- ---

Bogado.net

Function template resolution

There are two step to resolve what function to use when calling a templated functions.

  • solve all arguments in parallel.

  • verify if there’s any inconsistency.

    #include <iostream>
    
    template <class A, class B>
    void function(A a, B b) {
        std::cout << __PRETTY_FUNCTION__ << "\n";
    }
    
    int main() {
        function(10, 20); // void function(A, B) [with A = int; B = int]
        function("", 's'); // void function(A, B) [with A = const char*; B = char]
    }
  • parameter packs are greedy and will use as much options as possible.

  • Eliminate specialization if one or more parameters cannot be deduced.

  • Fail if more than one template matches.

  • Fail if all templates are eliminated.