MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / array

Function array

system/include/emscripten/val.h:289–306  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

287
288 template<typename Iter>
289 static val array(Iter begin, Iter end) {
290#if __cplusplus >= 202002L
291 if constexpr (std::contiguous_iterator<Iter> &&
292 internal::typeSupportsMemoryView<
293 typename std::iterator_traits<Iter>::value_type>()) {
294 val view{ typed_memory_view(std::distance(begin, end), std::to_address(begin)) };
295 return val(internal::_emval_new_array_from_memory_view(view.as_handle()));
296 }
297 // For numeric arrays, the following code is unreachable and the compiler
298 // will do 'dead code elimination'.
299 // Others fallback old way.
300#endif
301 val new_array = array();
302 for (auto it = begin; it != end; ++it) {
303 new_array.call<void>("push", *it);
304 }
305 return new_array;
306 }
307
308 template<typename T>
309 static val array(const std::vector<T>& vec) {

Calls 7

typed_memory_viewFunction · 0.85
to_addressFunction · 0.85
valFunction · 0.70
sizeMethod · 0.65
dataMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by 2

mainFunction · 0.40