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
This commit is contained in:
Chris Guzak 2018-04-09 08:16:18 -10:00 committed by Herb Sutter
parent 85db0de16c
commit e5f28e4095
2 changed files with 25 additions and 0 deletions

3
.gitignore vendored
View File

@ -4,3 +4,6 @@ node_modules
_site
scripts/python/__pycache__
scripts/python/*.pyc
# VS Code
.vs/

View File

@ -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.
### <a name="Rs-contained"></a>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 <string>
##### 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.
### <a name="Rs-namespace"></a>SF.20: Use `namespace`s to express logical structure
##### Reason