Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overloading template functions with different numbers of template parameters #3199

Open
mje-nz opened this issue Oct 20, 2019 · 0 comments

Comments

@mje-nz
Copy link
Contributor

@mje-nz mje-nz commented Oct 20, 2019

This works:

cdef extern from *: 
    """ 
    template<typename T> 
    T sum(T a, T b) { 
        return a + b; 
    } 
    template<typename T> 
    T sum(T a, T b, T c) { 
        return a + b + c; 
    } 
    """ 
    T sum[T](T a, T b) 
    T sum[T](T a, T b, T c) 
 
print(sum[int](1, 2)) 
print(sum[int](1, 2, 3)) 

This doesn't:

cdef extern from *: 
    """ 
    template<typename T1, typename T2> 
    T1 sum(T1 a, T2 b) { 
        return a + b; 
    } 
    template<typename T1, typename T2, typename T3> 
    T1 sum(T1 a, T2 b, T3 c) { 
        return a + b + c; 
    } 
    """ 
    T1 sum[T1, T2](T1 a, T2 b) 
    T1 sum[T1, T2, T3](T1 a, T2 b, T3 c) 
 
print(sum[int, int](1, 2)) 
print(sum[int, int, int](1, 2, 3)) 
Error compiling Cython file:
------------------------------------------------------------
...
    }
    """
    T1 sum[T1, T2](T1 a, T2 b)
    T1 sum[T1, T2, T3](T1 a, T2 b, T3 c)

print(sum[int, int](1, 2))
        ^
------------------------------------------------------------

test.pyx:15:9: Wrong number of template arguments: expected 3, got 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.