Boost logo

Boost :

Subject: Re: [boost] [core] Determining interest for two new classes: readonly and newtype
From: Sam Kellett (samkellett_at_[hidden])
Date: 2015-08-17 07:06:35

> This reminded me of something I hit recently: I wanted to have a bunch
> of fields to be const, but in one constructor I needed to initialize
> them in the constructor body, not in the initializer list.
> This created two problems. I thought I might be able to get around the
> first (of how to actually set them) by using casts; the second problem
> was the compiler warnings that I was not initializing all const members.
> I couldn't work that one out, so I gave up and removed const from all of
> them.

this is one of the main disadvantages (and discrepancy's against constness)
as you do not get a compiler error if your readonly variable is not in your
initializer list like you would with a const field.

> Would your readonly<T> have helped me here? (And, conversely, if it
> could, that implies the compiler cannot warn when they are not
> initialized?)

if i understand correctly i don't think readonly would help you here as
readonly, like const-fields can only be set at construction, so in the
initializer list. you would not be able to call any non-const methods on
your field in the constructor's body.

Boost list run by bdawes at, gregod at, cpdaniel at, john at