Skip to content

Pythonization of list to std::vector fails with function template #18838

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

Open
1 task
vepadulano opened this issue May 22, 2025 · 0 comments
Open
1 task

Pythonization of list to std::vector fails with function template #18838

vepadulano opened this issue May 22, 2025 · 0 comments

Comments

@vepadulano
Copy link
Member

Check duplicate issues.

  • Checked for duplicates

Description

Automatic conversion of a list[tuple[int, int]] to std::vector<std::pair<int, int>> fails in case the function called is a function template. It works in the case of a free function:

$: python repro.py
Using free function:
{(0, 2), (4, 7), (8, 9), }
Using function template:
Traceback (most recent call last):
  File "/Users/vpadulan/Programs/rootproject/rootcode/repro.py", line 28, in <module>
    ROOT.print_template(33., a)
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^
TypeError: Template method resolution failed:
  Failed to instantiate "print_template(double,std::initializer_list<std::initializer_list<int>>)"

Reproducer

import ROOT

ROOT.gInterpreter.Declare(r"""
template<typename T>
void print_template(T dummy, const std::vector<std::pair<int, int>> &vec)
{
    std::cout << "{";
    for (const auto &pair: vec)
        std::cout << "(" << pair.first << ", " << pair.second << "), ";
    std::cout << "}\n";
}

void print_free_function(float dummy, const std::vector<std::pair<int, int>> &vec)
{
    std::cout << "{";
    for (const auto &pair: vec)
        std::cout << "(" << pair.first << ", " << pair.second << "), ";
    std::cout << "}\n";
}
""")

a = [(0, 2), (4, 7), (8, 9)]

print("Using free function:")
ROOT.print_free_function(33., a)

print("Using function template:")
ROOT.print_template(33., a)

ROOT version

Any

Installation method

Any

Operating system

Any

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants