Revision control

Copy as Markdown

Other Tools

# C++ Reference
This page is a grab bag of useful links to C++ documentation in the Mozilla source docs or in the source code itself.
This will grow and gain organisation, so please add any links you find useful!
## Miscellaneous
- [XPIDL](https://firefox-source-docs.mozilla.org/xpcom/xpidl.html) - details for XPCOM IDL files (e.g. how the types map between IDL, C++, Rust and JS).
- [{fmt} in Gecko](https://firefox-source-docs.mozilla.org/xpcom/fmt-in-gecko.html) - An implementation of C++20’s `std::format` formatting API, with some extra Mozilla goodies.
## Data structures
- [String Guide](https://firefox-source-docs.mozilla.org/xpcom/stringguide.html) - `nsString` vs `nsCString` vs `nsACString` et al.
- [C++ and Mozilla standard libraries](https://firefox-source-docs.mozilla.org/code-quality/coding-style/using_cxx_in_firefox_code.html#c-and-mozilla-standard-libraries) - Guidelines for using standard C++ containers and libraries.
- [nsTArray](https://searchfox.org/firefox-main/source/xpcom/ds/nsTArray.h#99) - Analogous to `std::vector`.
Probably prefer these to `nsTHashMap`/`nsTHashSet`, which use a lot more virtual calls and less templating/inlining.
## Utility
- [Maybe](https://searchfox.org/firefox-main/source/mfbt/Maybe.h#315) - Analogous to Rust `Option<>` or C++ std::optional<T> (examples in [GTest](https://searchfox.org/firefox-main/source/mfbt/tests/TestMaybe.cpp)).
- [ScopeExit](https://searchfox.org/firefox-main/source/mfbt/ScopeExit.h) - An RAII guard to automatically handle scoped cleanup.