Skip to content

Commit 8954873

Browse files
fix: method resolution to convert initializer_list to vector (#153)
1 parent ddd69ad commit 8954873

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

clingwrapper/src/clingwrapper.cxx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,19 @@ bool Cppyy::AppendTypesSlow(const std::string& name,
573573
if (name.empty())
574574
return true;
575575

576+
auto replace_all = [](std::string& str, const std::string& from, const std::string& to) {
577+
if(from.empty())
578+
return;
579+
size_t start_pos = 0;
580+
while((start_pos = str.find(from, start_pos)) != std::string::npos) {
581+
str.replace(start_pos, from.length(), to);
582+
start_pos += to.length();
583+
}
584+
};
585+
586+
std::string resolved_name = name;
587+
replace_all(resolved_name, "std::initializer_list<", "std::vector<"); // replace initializer_list with vector
588+
576589
// We might have an entire expression such as int, double.
577590
static unsigned long long struct_count = 0;
578591
std::string code = "template<typename ...T> struct __Cppyy_AppendTypesSlow {};\n";
@@ -581,7 +594,7 @@ bool Cppyy::AppendTypesSlow(const std::string& name,
581594

582595
std::string var = "__Cppyy_s" + std::to_string(struct_count++);
583596
// FIXME: We cannot use silent because it erases our error code from Declare!
584-
if (!Cpp::Declare(("__Cppyy_AppendTypesSlow<" + name + "> " + var +";\n").c_str(), /*silent=*/false)) {
597+
if (!Cpp::Declare(("__Cppyy_AppendTypesSlow<" + resolved_name + "> " + var +";\n").c_str(), /*silent=*/false)) {
585598
TCppType_t varN = Cpp::GetVariableType(Cpp::GetNamed(var.c_str()));
586599
TCppScope_t instance_class = Cpp::GetScopeFromType(varN);
587600
size_t oldSize = types.size();
@@ -595,7 +608,7 @@ bool Cppyy::AppendTypesSlow(const std::string& name,
595608
// We should consider eliminating the `split_comma_saparated_types` and `is_integral`
596609
// string parsing.
597610
std::vector<std::string> individual_types;
598-
if (!split_comma_saparated_types(name, individual_types))
611+
if (!split_comma_saparated_types(resolved_name, individual_types))
599612
return true;
600613

601614
for (std::string& i : individual_types) {

0 commit comments

Comments
 (0)