Skip to content

Commit e5f28e4

Browse files
ChrisGuzakhsutter
authored andcommitted
SF.11, Header files should be self-contained (isocpp#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
1 parent 85db0de commit e5f28e4

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ node_modules
44
_site
55
scripts/python/__pycache__
66
scripts/python/*.pyc
7+
8+
# VS Code
9+
.vs/

CppCoreGuidelines.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18207,6 +18207,7 @@ Source file rule summary:
1820718207
* [SF.8: Use `#include` guards for all `.h` files](#Rs-guards)
1820818208
* [SF.9: Avoid cyclic dependencies among source files](#Rs-cycles)
1820918209
* [SF.10: Avoid dependencies on implicitly `#include`d names](#Rs-implicit)
18210+
* [SF.11: Header files should be self-contained](#Rs-contained)
1821018211

1821118212
* [SF.20: Use `namespace`s to express logical structure](#Rs-namespace)
1821218213
* [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
1861418615
Enforcement would require some knowledge about what in a header is meant to be "exported" to users and what is there to enable implementation.
1861518616
No really good solution is possible until we have modules.
1861618617

18618+
### <a name="Rs-contained"></a>SF.11: Header files should be self-contained
18619+
18620+
##### Reason
18621+
18622+
Usability, headers should be simple to use and work when included on their own.
18623+
Headers should encapsulate the functionality they provide.
18624+
Avoid clients of a header having to manage that header's dependencies.
18625+
18626+
##### Example
18627+
18628+
#include "helpers.h"
18629+
// helpers.h depends on std::string and includes <string>
18630+
18631+
##### Note
18632+
18633+
Failing to follow this results in difficult to diagnose errors for clients of a header.
18634+
18635+
##### Enforcement
18636+
18637+
A test should verify that the header file itself compiles or that a cpp file which only includes the header file compiles.
18638+
1861718639
### <a name="Rs-namespace"></a>SF.20: Use `namespace`s to express logical structure
1861818640

1861918641
##### Reason

0 commit comments

Comments
 (0)