| 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) { |