At 4/4/16 02:54 PM, Sam wrote:
It being trivial is kind of my argument that it should be in the standard library. Again, it's probably because I'm switching between Python which cradles you with a function for everything and C++ for this project.
Beats me as to why the STL doesn't contain it; there really isn't any compelling reason for it on modern systems (makes sense that it wouldn't be included back in the 80s).
It might end up in C++14. Who knows?
At 4/4/16 02:54 PM, Sam wrote:
But I can't (from memory) see any information in the header file that couldn't be included or is already defined in the source file.
Headers generally don't contain definitions; they're supposed to be used for declarations, except for edge-cases where you have no choice but to include the definition in your header (such as when using templates).
The header is basically the skeleton of the source file, whereas the source file is where all the meaty goodness is.
Another way to think about it is how you have to declare your member variables in a class before you can ever use them in some OO languages (e.g. ActionScrupt, C#, Java).
At 4/4/16 02:54 PM, Sam wrote:
Couldn't headers be generated automatically as part of a pre-compile process?
No.
The compiler wouldn't know what is and what isn't supposed to be exposed by the header file, which could cause it to put things in the header that don't belong which could end up breaking an application. The only option it would have is to include absolutely everything that is in the source file, and if you have a function in your source file with the same name as a function in another source file, and both of those headers are automatically generated and both included somewhere else: KABLAMO! COMPILER ERROR!
When it comes down to it: the header file is there to publicly expose parts of the source file. If you put a class, function, or variable inside of a source file, and do not declare it in the header file, then absolutely nothing outside of that one single source file can ever access it. Inversely, if you do include it in the header file, then anything that includes that header file will have access to it.