wjakob / nanobind

nanobind: tiny and efficient C++/Python bindings
BSD 3-Clause "New" or "Revised" License
2.14k stars 161 forks source link

[BUG]: iterator_category of wrong type #576

Closed juanjosegarciaripoll closed 1 month ago

juanjosegarciaripoll commented 1 month ago

Problem description

It seems the iterator types in nanobind do not fulfill all requirements for c++17, according to Visual Code. Apologies for the error message being in Spanish, but it basically says that nanobind::iterator::iterator_category has the wrong type.

  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include\xutility(806,54): error C2794: 'iterator_category': no es miembro de ninguna clase base directa ni indirecta de 'std::iterator_traits<_Iter>' [C:\Users\juanj\src\seemps5\build\cp312-cp312-win_amd64\core.vcxproj]
            with
            [
                _Iter=nanobind::iterator
            ] (compilando archivo de origen C:\Users\juanj\src\seemps5\src\seemps\state\tools.cc)

Reproducible example code

namespace nanobind {

list make_list(Py_ssize_t len) { return list(PyList_New(len)); }

list make_list(Py_ssize_t len, object o) {
  list output = make_list(len);
#if 0
  for (auto &x : output) {
    x = o;
  }
#else
  std::fill(output.begin(), output.end(), o);
#endif
  return output;
}

}
wjakob commented 1 month ago

nanobind iterators aren't C++17 iterators. They cannot be, to my knowledge. For example, some operations (like copying an iterator) would not even work since the iterators hold a reference to a Python iterator that is modified each time operator++ is called.