Is there a preferred order of include files? Boost or std first?

I have been wondering if there is a preferred order of include files? Should I write (for example): #include <iostream> #include <boost/test/unit_test.hpp> or #include <boost/test/unit_test.hpp> #include <iostream> Or does it not matter? There seems no clear consistency in Boost files Paul PS IMO It would helpful to those reading code to have a consistent order. -- Paul A Bristow Prizet Farmhouse, Kendal, Cumbria UK LA8 8AB Phone and SMS text +44 1539 561830, Mobile and SMS text +44 7714 330204 mailto: pbristow@hetp.u-net.com http://www.hetp.u-net.com/index.html http://www.hetp.u-net.com/Paul%20A%20Bristow%20info.html

"Paul A Bristow" <pbristow@hetp.u-net.com> writes:
I have been wondering if there is a preferred order of include files?
Should I write (for example):
#include <iostream> #include <boost/test/unit_test.hpp>
or
#include <boost/test/unit_test.hpp> #include <iostream>
Or does it not matter?
I try to choose an order that will expose headers that fail to #include all the headers on which they depend. That means standard headers always come after boost headers. -- Dave Abrahams Boost Consulting www.boost-consulting.com

Should I write (for example):
#include <iostream> #include <boost/test/unit_test.hpp>
or
#include <boost/test/unit_test.hpp> #include <iostream>
Or does it not matter?
I try to choose an order that will expose headers that fail to #include all the headers on which they depend. That means standard headers always come after boost headers.
The same here. Unfortunately this practice is exactly opposite to precompiler headers one. Gennadiy

Should I write (for example):
#include <iostream> #include <boost/test/unit_test.hpp>
or
#include <boost/test/unit_test.hpp> #include <iostream>
Or does it not matter?
It might matter, because there could be macros in standard libraries
Gennadiy Rozental wrote: that conflict with those in the Boost libraries, although I'm sure Boost developers take pains to avoid this doing this. I always go by the principle that older definitions should take precedence over newer ones and so put standard libraries before Boost libraries (the opposite of what has been advised by David Abrahams) and then include own header files after that. As Boost developers are nod oubt careful not to redefine anything in standard libraries, I suppose the order doesn't make any difference. Those more familiar with the way compilers work might be able to say whether or not this is the case. Paul
participants (4)
-
David Abrahams
-
Gennadiy Rozental
-
Paul A Bristow
-
Paul Giaccone