Boost logo

Geometry :

Subject: [ggl] Convention of headers inclusion
From: Mateusz Loskot (mateusz)
Date: 2009-04-12 16:19:39


Mateusz Loskot wrote:
> Hi,
>
> Is there any convention about order in which std, boost and ggl
> headers should be included in GGL code? Sometimes order of headers
> may cause different behaviour on different C++ implementations, for
> instance by implicit inclusion (or lack of) of some headers.
>
> What's the suggested order of std, boost and ggl headers included in
> ggl code?

Example of potential problems caused by implicit inclusion is in
file test/circle.cpp which includes:

#include <geometry/geometries/nsphere.hpp>
#include <geometry/core/concepts/nsphere_concept.hpp>

Reordering these two to include the concept first:

#include <geometry/core/concepts/nsphere_concept.hpp>
#include <geometry/geometries/nsphere.hpp>

gives compilation error:

In file included from circle.cpp:13:
../../geometry/core/concepts/nsphere_concept.hpp: In destructor
?geometry::ConstNsphere<S>::~ConstNsphere()?:
../../geometry/core/concepts/nsphere_concept.hpp:60: error: ?dimension?
was not declared in this scope
../../geometry/core/concepts/nsphere_concept.hpp:60: error: expected
primary-expression before ?>? token
../../geometry/core/concepts/nsphere_concept.hpp:60: error: ?::value?
has not been declared
../../geometry/core/concepts/nsphere_concept.hpp:61: error: ?N? is not a
valid template argument for type ?long unsigned int? because it is a
non-constant expression
../../geometry/core/concepts/nsphere_concept.hpp:61: error: invalid type
in declaration before ?;? token
../../geometry/core/concepts/nsphere_concept.hpp:62: error: ?N? is not a
valid template argument for type ?long unsigned int? because it is a
non-constant expression
../../geometry/core/concepts/nsphere_concept.hpp:62: error: invalid type
in declaration before ?;? token
../../geometry/core/concepts/nsphere_concept.hpp: In destructor
?geometry::Nsphere<S>::~Nsphere()?:
../../geometry/core/concepts/nsphere_concept.hpp:107: error: ?dimension?
was not declared in this scope
../../geometry/core/concepts/nsphere_concept.hpp:107: error: expected
primary-expression before ?>? token
../../geometry/core/concepts/nsphere_concept.hpp:107: error: ?::value?
has not been declared
../../geometry/core/concepts/nsphere_concept.hpp:108: error: ?N? is not
a valid template argument for type ?long unsigned int? because it is a
non-constant expression
../../geometry/core/concepts/nsphere_concept.hpp:108: error: invalid
type in declaration before ?;? token
../../geometry/core/concepts/nsphere_concept.hpp:109: error: ?N? is not
a valid template argument for type ?long unsigned int? because it is a
non-constant expression
../../geometry/core/concepts/nsphere_concept.hpp:109: error: invalid
type in declaration before ?;? token

This is because <geometry/core/concepts/nsphere_concept.hpp> uses
dimension type but does include coordinate_dimension.hpp, which in the
original (working) version is included implicitly/indirectly by
<geometry/geometries/nsphere.hpp>

AFAIU, actual fix for this is to add following line to header
<geometry/core/concepts/nsphere_concept.hpp>:

#include <geometry/core/coordinate_dimension.hpp>

Then, inclusion of only nsphere_concept.hpp header will work.

Best regards,

-- 
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org

Geometry list run by mateusz at loskot.net