Subject: [boost] Header Inclusion practices
From: Robert Ramey (ramey_at_[hidden])
Date: 2017-04-11 17:55:58
As long as I can remember, it's been my practice to write program code
to minimize dependencies on the environment in which it is built. By
environment I mean things external to the code itself like environmental
and command line variables, directory context etc. As part of this I
use rules for header file inclusion:
a) use #include "header.hpp" for files in the same directory as the
current source file.
b) use #include "other directory/header.hpp" for files which are known
to be in a specific place relative to the current file. This shows up
in things like: #include "../include/header.hpp" for tests and examples.
c) use #include <boost/serialization/xml_archive.hpp> for files which
are found by looking in directories listed in "-I" switches and
environmental variables (INCLUDE). I generally try not to depend upon
any environmental variables as I always forget to set them or even how
to set them. Come to think about it. I don't know how my build system
finds the boost libraries. I presume it's through some IDE/Bjam/CMake
setting which I can never remember.
d) use #include <iostream> for standard library components. Presumably
these are routed to some directory relative to the compiler.
So some of my source files look like:
// interval.hpp header for safe numerics library
#include "utility.hpp" // log
// example using he safe numerics library
This has raised consternation in some quarters - but I don't see
anything wrong with it. It basically means that only the <boost
libraries are depended on the whole b2 business. I didn't want the
incubator version of the the safe numeric library to depend on the
library having been accepted into boost have have b2 run. Also I don't
like adding the library to boost - and having to change all the headers.
What if someone want's to run the tests/examples outside of the boost
As far as I know this question has never been asked before and I'm
curious to know what others might have to say about this.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk