From: Iain Denniston (iain.denniston_at_[hidden])
Date: 2007-08-15 06:14:37
> 1. Is it a generalization of the std::ios_base::flags approach?
As I understand it std::ios_base::flags will accept any integer - valid
or otherwise. My library would be used to prevent invalid integers being
passed (though would require valid flags be members of a single enum).
Obviously in the case of std::ios_base::flags it would require a rewrite
so's the argument would be of type boost::flags<...>
>> func2(flags<foo>(foo_1) | foo_2 | bar_1 | bar_2); //Compile time error
> 2. It'd be more convenient without <CODE>flags<foo>(...)</CODE>
> conversion, wouldn't it?
It would be - and initially that was the idea, just that the compiler
gets confused (least vc8 does). If you are passing a single flag it's
fine (you can omit the flags<foo>(...) ) - if you're passing multiple
flags the only way I could think of making it work would be to provide a
constructor that accepts integers - which would defeat the purpose of
the library. Somebody cleverer and more well versed in C++ than I am
might be able to suggest an alternative though.
> 3. Can <CODE>flags<foo>(foo_1) | foo_2</CODE> be used as a compile-time
I'm not sure I entirely understand what you are getting at here - what
is it you want to do? If you mean you want to have access to the value
stored in the flags class at compile time then I'd have thought that's
not possible - but I can't see why that would be a problem.
Alternatively if you mean will flags<foo>(foo_1) | foo_2 compile out to
a single value I think that would depend on the compiler - certainly the
template is ideal for inlining and once inlined it becomes identical to
the |'ing of integer values, so could easily be reduced to a single value.
Otherwise you've lost me :o)
Hope that helps - if not give me a shout and I'll try and give better
answers. Apologies if I've misunderstood anything.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk