Boost logo

Boost :

From: spamjunk_at_[hidden]
Date: 2002-08-27 10:19:45


To do what you want to do with the discrete_set class is possible. You just
need to fix two problems in your code example:

1. First, you need to get rid of the undefined behavior. Either change the
element type to int, or your enum must allow for the range of values you need.
The easiest way to do that is to just add the max and min values to your enum
definition.

2. You can't test for membership with an element that is not in the set's
universe. You need to set the HI and LO template parameters to the max and min
values you need. Note, though, this will create very large set objects if your
range is great.

This should give you what you want.

Rich Herrick

> You wrote:
> > -----Original Message-----
> > From: spamjunk_at_[hidden] [mailto:spamjunk_at_[hidden]]
> > Sent: Tuesday, August 27, 2002 2:47 PM
> > To: boost_at_[hidden]
> > Subject: RE: [boost] discrete_set class
> >
> >
> > Ok, this is my fault. As Joel has pointed out, I neglected to provide
> > documentation. I apologize and will upload some as soon as I
> > can. For now, the
> > problem with your examples is the class expects the values of
> > the elements to be
> > in the range [LO, HI]. You are trying to use values outside
> > the range. My
> > understanding of C++ is that it is undefined behavior to
> > convert an int to an
> > enum when it is outside the enum's range.
>
> I agree with you. But explain me smth, please.
> In database table I keep integers( numeric) values.
> I have to construct my objects from table record.
> I have to test whether value from database is valid enum or not.
> I build discrete_set that contains all enums. (They don't have to be
sequential, very
important to me).
> And now I am going to test using contain function. At first I must use
static_cast to
convert
> value to enum(I don't like it) and then I have to test.
> What is wrong with this scenario. And if your class doesn't give a solution
for this
> problem, than what problem you are trying to solve?
>
>
> > pop-server.stny.rr.com
> >
> > _______________________________________________
> > Unsubscribe & other changes:
> > http://lists.boost.org/mailman/listinfo.cgi/boost
> >
>
>
> Roman
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

pop-server.stny.rr.com


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