Boost logo

Boost :

From: Edward Diener (eddielee_at_[hidden])
Date: 2003-10-04 16:42:31

Bronek Kozicki wrote:
> Edward Diener <eddielee_at_[hidden]> wrote:
>> The getter, setter property technique is much more general than what
>> I suggested with my query about implementing ranges and/or specific
>> At the type level, one might perhaps be able to specify the ranges
>> and/or values with some sort of typelist of non-type template
>> parameters. At the variable level, one might be able to do it in the
> I think that right solution would involve list of non-type template
> parameters, which would allow static control of ranges at type level.

I agree, but how this list would be specified and generated is the question.

> There is place for runtime range control, though:
> * as a tool which can be used in implementation of user defined
> operators (especially - + *) and conversions
> * as a specific implementation of getter/setter interface

A getter interface can just return a value. A setter interface can be
implemented by creating an assignment operator which checks the value being
assigned against the possible ranges and values. But I don't think it is
necessary to have either one if one just does the latter, ie. implements the
assignment operator. If in the assignment operator the value is not a valid
value, one can ignore ignore the assignment completely or do something like
throw an exception or generate an assert.

As far as callbacks to the target class, if by target you mean the type of
the value, the callback member function would have to be passed to a member
function or the constructor of the template class in some way, preferably
via a boost::function.

My interest lies more in the possibility first mentioned, which is
generating a list of non-type template parameters which would adequately
specify the acceptable values for the assignment operator to check. I don't
know if this can really be done but I expect some template magic could do
it. One would also need to dsitinguish ranges from specific values and allow
for things like disontinuous ranges, or all odd values, or every value
evenly dividable by some amount etc. etc. Working out a plan to do all this
might be fun but it would be difficult programming. If one were merely to do
single range checking in this way, even that might be a challenge. But I
have a feeling that even such templated single range-checked types might be
very valuable to many programmers. The alternative of non-templated classes
and getters and setters ( or properties if you will ) surely works but it is
much more laborious to re-create each time. Surely a templated class which
one could use over a large number of types, let's say just the built-in
integer types, would be useful.

> I also think that more general getter/setter (possibly allowing
> callbacks to "target" class) would fit in this picture.

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