From e5f28e4095d979cc4cd2d8cf426fe87e0d28962a Mon Sep 17 00:00:00 2001 From: Chris Guzak Date: Mon, 9 Apr 2018 08:16:18 -1000 Subject: [PATCH] SF.11, Header files should be self-contained (#1181) * SF.11 Header files should be self-sufficient added * PR feedback addressed * explain more * update reason baed on PR feedback * add VS code dir to .gitignore * more PR feedback --- .gitignore | 3 +++ CppCoreGuidelines.md | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/.gitignore b/.gitignore index a828547..9755634 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ node_modules _site scripts/python/__pycache__ scripts/python/*.pyc + +# VS Code +.vs/ \ No newline at end of file diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index c1ca22c..37b322f 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -18207,6 +18207,7 @@ Source file rule summary: * [SF.8: Use `#include` guards for all `.h` files](#Rs-guards) * [SF.9: Avoid cyclic dependencies among source files](#Rs-cycles) * [SF.10: Avoid dependencies on implicitly `#include`d names](#Rs-implicit) +* [SF.11: Header files should be self-contained](#Rs-contained) * [SF.20: Use `namespace`s to express logical structure](#Rs-namespace) * [SF.21: Don't use an unnamed (anonymous) namespace in a header](#Rs-unnamed) @@ -18614,6 +18615,27 @@ This rule against implicit inclusion is not meant to prevent such deliberate agg Enforcement would require some knowledge about what in a header is meant to be "exported" to users and what is there to enable implementation. No really good solution is possible until we have modules. +### SF.11: Header files should be self-contained + +##### Reason + +Usability, headers should be simple to use and work when included on their own. +Headers should encapsulate the functionality they provide. +Avoid clients of a header having to manage that header's dependencies. + +##### Example + + #include "helpers.h" + // helpers.h depends on std::string and includes + +##### Note + +Failing to follow this results in difficult to diagnose errors for clients of a header. + +##### Enforcement + +A test should verify that the header file itself compiles or that a cpp file which only includes the header file compiles. + ### SF.20: Use `namespace`s to express logical structure ##### Reason