
Boost : 
Subject: Re: [boost] [Review] GGL review starts today, November 5th
From: Mateusz Loskot (mateusz_at_[hidden])
Date: 20091119 18:17:19
Brandon Kohn wrote:
> Dimensionally qualified quantities can be calculated for geometries for
> whose dimensions the quantity makes no sense (e.g. area( point ),
> length( point ).) These functions return default constructed instances
> of their corresponding return type as shown here:
>
> template<typename ReturnType, typename Geometry, typename Strategy>
> struct calculate_null
> {
> static inline ReturnType apply(Geometry const& , Strategy const&)
> {
> return ReturnType();
> }
> };
>
> In my test ReturnType was double. This would seem to silently compile
> and return garbage on these inputs. In practice on vs2008( VC9 ) these
> return values were 0 (with optimizations on) even though the return
> resolves to double();. I'm guessing other platforms won't be so lucky.
This expression is correct and well defined.
If I may, here is reference from the C++ standard document:
"""
5.2.3 Explicit type conversion (functional notation)
2 The expression T(), where T is a simpletypespecifier (7.1.5.2) for
a nonarray complete object type or the (possibly cvqualified)
void type, creates an rvalue of the specified type, which is
valueinitialized (8.5; no initialization is done for the void() case).
"""
and
"""
5 To zeroinitialize an object of type T means:
— if T is a scalar type (3.9), the object is set to the value of 0
(zero) converted to T;
— if T is a nonunion class type, each nonstatic data member and each
baseclass subobject is zero
initialized;
— if T is a union type, the object’s first named data member89) is
zeroinitialized;
— if T is an array type, each element is zeroinitialized;
— if T is a reference type, no initialization is performed.
To defaultinitialize an object of type T means:
— if T is a nonPOD class type (clause 9), the default constructor for
T is called (and the initialization is
illformed if T has no accessible default constructor);
— if T is an array type, each element is defaultinitialized;
— otherwise, the object is zeroinitialized.
To valueinitialize an object of type T means:
— if T is a class type (clause 9) with a userdeclared constructor
(12.1), then the default constructor for T is
called (and the initialization is illformed if T has no
accessible default constructor);
— if T is a nonunion class type without a userdeclared constructor,
then every nonstatic data member and baseclass component of T
is valueinitialized;
— if T is an array type, then each element is valueinitialized;
— otherwise, the object is zeroinitialized
A program that calls for defaultinitialization or valueinitialization
of an entity of reference type is illformed. If T is a cvqualified
type, the cvunqualified version of T is used for these definitions of
zeroinitialization, defaultinitialization, and valueinitialization.
"""
Best regards,
 Mateusz Loskot, http://mateusz.loskot.net Charter Member of OSGeo, http://osgeo.org
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk