Skip to content

Commit 9637bd2

Browse files
committed
Add a table listing STL datatypes and their Godot equivalents in C++ usage guidelines
This is more comprehensive than the previous advice.
1 parent 9a2b56e commit 9637bd2

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

contributing/development/cpp_usage_guidelines.rst

+30-7
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,39 @@ See :ref:`doc_faq_why_not_stl` for more information.
5555
This means that pull requests should **not** use ``std::string``,
5656
``std::vector`` and the like. Instead, use Godot's datatypes as described below:
5757

58-
- Use ``String`` instead of ``std::string``.
59-
- Use ``Vector`` instead of ``std::vector``. In some cases, ``LocalVector``
60-
can be used as an alternative (ask core developers first).
61-
- Use ``Array`` instead of ``std::array``.
58+
+------------------------+----------------------------+-------------------------------------------+
59+
| C++ STL datatype | Recommended Godot datatype | Alternative Godot datatype* |
60+
+========================+============================+===========================================+
61+
| ``std::string`` | ``String`` | ``StringName`` |
62+
+------------------------+----------------------------+-------------------------------------------+
63+
| ``std::vector`` | ``Vector`` | ``LocalVector`` |
64+
+------------------------+----------------------------+-------------------------------------------+
65+
| ``std::array`` | ``Array`` | ``TypedArray`` |
66+
+------------------------+----------------------------+-------------------------------------------+
67+
| ``std::span`` | ``Span`` | |
68+
+------------------------+----------------------------+-------------------------------------------+
69+
| ``std::set`` | ``HashSet`` | ``RBSet`` |
70+
+------------------------+----------------------------+-------------------------------------------+
71+
| ``std::map`` | ``OAHashMap`` | ``AHashMap``, ``HashMap``, ``Dictionary`` |
72+
+------------------------+----------------------------+-------------------------------------------+
73+
| ``std::unordered_map`` | ``OAHashMap`` | ``AHashMap``, ``HashMap``, ``Dictionary`` |
74+
+------------------------+----------------------------+-------------------------------------------+
75+
| ``std::pair`` | ``Pair`` | |
76+
+------------------------+----------------------------+-------------------------------------------+
77+
| ``std::variant`` | ``Variant`` | |
78+
+------------------------+----------------------------+-------------------------------------------+
79+
80+
\*: For certain use cases, this alternative datatype is more performant or has
81+
characteristics that are more suitable for the task at hand. However, it is not
82+
always a direct replacement for the recommended datatype. Ask for advice if you
83+
are unsure.
6284

6385
.. note::
6486

65-
Godot also has a List datatype (which is a linked list). While List is already used
66-
in the codebase, it typically performs worse than other datatypes like Vector
67-
and Array. Therefore, List should be avoided in new code unless necessary.
87+
Godot also has a ``List`` datatype (which is a linked list). While ``List``
88+
is already used in the codebase, it typically performs worse than other
89+
datatypes like ``Vector`` and ``Array``. Therefore, ``List`` should be
90+
avoided in new code unless necessary.
6891

6992
``auto`` keyword
7093
~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)