|
Boost : |
From: Daryle Walker (darylew_at_[hidden])
Date: 2005-09-26 02:51:29
On 9/25/05 7:02 PM, "Robert Kawulak" <kawulak_at_[hidden]> wrote:
>> Restricted is ok, but I like constrained better. Please see:
>>
>> http://www.boost.org/doc/html/constrained_value.html
>> http://www.boost.org/boost/date_time/constrained_value.hpp
>> http://www.artima.com/weblogs/viewpost.jsp?thread=79470
>>
>> Jeff
[SNIP]
> BTW, constrained_value of Christofer Diggins has at least one 'bug' - it has
> a default constructor which default-initialises the value, and doesn't check
> if this default value conforms to the constraints. I also believe, that it'd
> be better to supply operator const value() than operator value() - this
> conversion is implicit so the const version would be safer.
Why bother with the "const"? The usage will already return a r-value, i.e.
a temporary. The kinds of mutable operations that can be done on it are
already restricted. The only times I've seen mutable operations on such
values are ones that were deliberately done. The "const" adds nothing but
annoyance; the safety-conscious won't need it since they wouldn't try
mutable code, and the programmers that want to abuse a mutable operation
would be upset that you locked them out. It's the same kind of controversy
about (member) functions returning non-reference objects with "const"
attached. (And we seen "cute" tricks in C++ made for our "benefit"
back-fire later, like std::vector<bool>.)
-- Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk