diff --git a/libcxx/docs/Contributing.rst b/libcxx/docs/Contributing.rst --- a/libcxx/docs/Contributing.rst +++ b/libcxx/docs/Contributing.rst @@ -55,6 +55,28 @@ 4. Create a submodule in ``include/module.modulemap`` for the new header. 5. Update the ``include/CMakeLists.txt`` file to include the new header. +Header layout +============= + +Libc++ uses small and contained headers to implement various features. For example, if +you were going to implement the ``std::ranges::size`` customization point object, you might +consider creating a new header to house this new feature. + +There are a few things to keep in mind when creating new headers: + +* The headers should only go one level deep. This means you could create a header named + ``__memory/shared_ptr.h``, but you couldn't create a header + ``__memory/smart_pointers/shared_ptr.h``. +* All sub-directories should be mangled with a double underscore. Conversely, headers + that live in these directories should not be mangled. +* Headers should contain specific features. A header such as ``__detail/utils.h`` might + turn into a dumping ground for "random" utilities. This is counterproductive and actually + makes things harder to find. +* All sub-headers should be included by their parent header. To use the example above, + it is imperative that ```` includes the sub-header ``__ranges/size.h``. Or, to use + another example, ```` must include ``__iterator/iterator_traits.h``, even if it + doesn't use ``iterator_traits`` itself. + Exporting new symbols from the library ======================================