Boost logo

Boost :

From: Joachim Faulhaber (afojgo_at_[hidden])
Date: 2008-05-27 17:06:19


2008/5/27 David Abrahams <dave_at_[hidden]>:
>
>> The one property of boost::date_time that knocked my socks off was the
>> default constructor that 'is-not-a-date-time'. I paraphrase this as:
>> boost::time is lacking a big bang ;-)
>>
>> Default constructors in nearly all the types that I've seen in my
>> lifetime (I know the realm of my unknown unknowns is vast ;-) are
>> intended to be elements of the type they do construct.
>
> Well, sure, but the built-ins in C++ generally default construct as
> singular "degenerate" elements that you can assign to and destruct, and
> nothing else.
>
My generic library code has no problem with the 'value nature' of
built in types. Because from the initial default constructed value

unsigned int x = int(); // x = 0 you can reach
++x // x = 1
...
++x // x = 2^32

and thus all values of the types set of values.

This is not the case for boost::date_time objects like e.g.
ptime

ptime x = ptime(); // x = "not-a-date-time"
                           // ++x error ++ not available
x += ptime::time_duration_type::unit(); // x = "not-a-date-time"
...
x += ptime::time_duration_type::unit(); // x = "not-a-date-time"

no element of the set of values of ptime is reachable from the
default ctor with any available ptime operations or functions.

>> Moreover in so many cases including built in types, default ctors
>> serve as *initial elements*. Other elements can be *reached* from T()
>> applying operations of T on them.
>>
>> This applies to all built in types
>
> You must be thinking of value-initialization. Please read
> http://www.boost.org/doc/libs/1_35_0/libs/utility/value_init.htm
>
This is helpful in general. Yet, as far as I can see no remedy
for the singularity default constructor problem that I had with
boost::date_time

 value_initialized<ptime> x; // x = "not-a-date-time"
                                        // ++x error ++ not available
x += ptime::time_duration_type::unit(); // x = "not-a-date-time"
...
x += ptime::time_duration_type::unit(); // x = "not-a-date-time"

same problems.

I am not yet able to discover the advantages of such default ctor
construction especially if it derails generic code that works well
with standard types.

Regards
Joachim

---
Interval Template Library (ITL)
download from  http://sourceforge.net/projects/itl
documentation  http://www.herold-faulhaber.de/

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk