aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sol2/docs/source/api/as_container.rst
diff options
context:
space:
mode:
authorAndy Belle-Isle <drumsetmonkey@gmail.com>2019-08-30 00:45:36 -0400
committerAndy Belle-Isle <drumsetmonkey@gmail.com>2019-08-30 00:45:36 -0400
commitdc2493e7525bb7633f697ef10f72b72b46222249 (patch)
tree9816755219e65d3f47fdce81c78f3736a7ddb8ab /lib/sol2/docs/source/api/as_container.rst
parent9d2b31797d0cfd130802b69261df2cd402e39b49 (diff)
Forget what I said, I just need to change git attributes to mark for vendor
Diffstat (limited to 'lib/sol2/docs/source/api/as_container.rst')
-rw-r--r--lib/sol2/docs/source/api/as_container.rst23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/sol2/docs/source/api/as_container.rst b/lib/sol2/docs/source/api/as_container.rst
new file mode 100644
index 0000000..917cebb
--- /dev/null
+++ b/lib/sol2/docs/source/api/as_container.rst
@@ -0,0 +1,23 @@
+as_container
+============
+*force a type to be viewed as a container-type when serialized to Lua*
+
+.. code-block:: cpp
+
+ template <typename T>
+ struct as_returns_t { ... };
+
+ template <typename T>
+ as_returns_t<T> as_returns( T&& );
+
+
+Sometimes, you have a type whose metatable you claim with a usertype metatable via :doc:`usertype semantics<usertype>`. But, it still has parts of it that make it behave like a container in C++: A ``value_type`` typedef, an ``iterator`` typedef, a ``begin``, an ``end``, and other things that satisfy the `Container requirements`_ or the `Sequence Container requirements`_ or behaves like a `forward_list`_.
+
+Whatever the case is, you need it to be returned to Lua and have many of the traits and functionality described in the :doc:`containers documentation<../containers>`. Wrap a return type or a setter in ``sol::as_container( value );`` to allow for a type to be treated like a container, regardless of whether ``sol::is_container`` triggers or not.
+
+See `this container example`_ to see how it works.
+
+.. _this container example: https://github.com/ThePhD/sol2/blob/develop/examples/source/container_usertype_as_container.cpp
+.. _Container requirements: http://en.cppreference.com/w/cpp/concept/Container
+.. _Sequence Container requirements: http://en.cppreference.com/w/cpp/concept/SequenceContainer
+.. _forward_list: http://en.cppreference.com/w/cpp/container/forward_list