MCPcopy Create free account
hub / github.com/pybind/pybind11 / convert_elements

Method convert_elements

include/pybind11/stl.h:393–410  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

391
392 template <bool R = Resizable, enable_if_t<R, int> = 0>
393 bool convert_elements(handle seq, bool convert) {
394 auto l = reinterpret_borrow<sequence>(seq);
395 value.reset(new ArrayType{});
396 // Using `resize` to preserve the behavior exactly as it was before PR #5305
397 // For the `resize` to work, `Value` must be default constructible.
398 // For `std::valarray`, this is a requirement:
399 // https://en.cppreference.com/w/cpp/named_req/NumericType
400 value->resize(l.size());
401 size_t ctr = 0;
402 for (const auto &it : l) {
403 value_conv conv;
404 if (!conv.load(it, convert)) {
405 return false;
406 }
407 (*value)[ctr++] = cast_op<Value &&>(std::move(conv));
408 }
409 return true;
410 }
411
412 template <bool R = Resizable, enable_if_t<!R, int> = 0>
413 bool convert_elements(handle seq, bool convert) {

Callers

nothing calls this directly

Calls 6

moveFunction · 0.85
resizeMethod · 0.80
emplace_backMethod · 0.80
sizeMethod · 0.45
loadMethod · 0.45
reserveMethod · 0.45

Tested by

no test coverage detected