Skip to content

extra empty names attributes generated by list::push_back #206

Closed
@mikejiang

Description

@mikejiang
#include "cpp11.hpp"
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace cpp11;
using namespace std;
  
[[cpp11::register]]
cpp11::writable::list test_cpp() {

  cpp11::writable::list res;
  for (int i = 0; i < 5; i++)
  {
    string chnl = "n" + std::to_string(i);
    res.push_back(cpp11::named_arg(chnl.c_str()) = i);
    auto d = cpp11::as_cpp<vector<string>>(res.names());
    for (auto j : d)
    {
      cout << j << ", ";
    }
    cout << endl;
  }
    return res;
  
}
> cpp11::cpp_source("~/Downloads/t.cpp")
> d = test_cpp()
n0, 
n0, n1, 
n0, n1, n2, , 
n0, n1, n2, n3, 
n0, n1, n2, n3, n4, , , , 
> names(d)
[1] "n0" "n1" "n2" "n3" "n4" ""   ""   ""  

As shown above, extra names attribute elements are generated and attached to result list.
Am I doing something wrong here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions