@@ -641,6 +641,41 @@ Classes
641641 :param typename... Policies: |policies-argument |
642642 :returns: |class_-function-returns |
643643
644+ .. cpp :function :: const class_& iterable () const
645+
646+ .. code-block :: cpp
647+
648+ // prototype
649+ template<typename ElementType>
650+ EMSCRIPTEN_ALWAYS_INLINE const class_& iterable(const char* sizeMethodName, const char* getMethodName) const
651+
652+ Makes a bound class iterable in JavaScript by installing ``Symbol.iterator ``.
653+ This enables use with ``for...of `` loops, ``Array.from() ``, and spread syntax.
654+
655+ :tparam ElementType: The type of elements yielded by the iterator. Used for
656+ TypeScript definition generation.
657+
658+ :param sizeMethodName: Name of the bound method that returns the number of elements.
659+ Must return ``size_t ``.
660+
661+ :param getMethodName: Name of the bound method that retrieves an element by index.
662+ Must accept a ``size_t `` index and return ``ElementType ``.
663+
664+ :returns: |class_-function-returns |
665+
666+ .. code-block :: cpp
667+
668+ class_<MyContainer>("MyContainer")
669+ .function("size", &MyContainer::size)
670+ .function("get", &MyContainer::get)
671+ .iterable<int>("size", "get");
672+
673+ .. code-block :: javascript
674+
675+ const container = new Module.MyContainer ();
676+ for (const item of container) { /* ... */ }
677+ const arr = Array .from (container);
678+
644679
645680 .. cpp :function :: const class_& property () const
646681
0 commit comments