Skip to content

Include Directives Order

Mateusz Łoskot edited this page Jan 8, 2020 · 5 revisions

The CONTRIBUTING guide recommends to make sure that headers are self-contained, i.e. that they include all headers they need. In other words, no header should (implicitly) rely on other headers to include some other header it requires.

One technique that helps to ensure a header is as self-contained as possible is to group include directives from specific to general and, for readability, order alphabetically within each group.

Order of #include in GIL core and extensions headers

  1. #include <boost/gil/extension/*.hpp>
  2. #include <boost/gil/*.hpp>
  3. #include <boost/*.hpp>
  4. C++ standard library headers
  5. Other third-party and system headers

Order of #include in tests

  1. #include "unit_test.hpp"
    #ifndef BOOST_TEST_MODULE
    #define BOOST_TEST_MODULE test_xxx
    #endif
    #include "unit_test.hpp"
  2. #include <boost/gil/*.hpp>
  3. #include <boost/*.hpp>
  4. C++ standard library headers
  5. Other third-party and system headers
  6. #include "test_fixture.hpp" and other local headers

Order of #include in examples and other programs

  1. #include <boost/gil/*.hpp>
  2. #include <boost/*.hpp>
  3. C++ standard library headers
  4. Other third-party and system headers
  5. #include "xxx.hpp" for directory local headers