|
Boost : |
From: Jeff Garland (jeff_at_[hidden])
Date: 2005-09-25 16:06:06
On Sun, 25 Sep 2005 22:08:32 +0200, Robert Kawulak wrote
> Hi group,
>
> > Some time ago I've written a set of class templates for
> > bounded types (types
> > whose variables may hold a value only from within a specified
> > range).
>
> Just today I've discovered, that basic_bounded class template is
> even more flexible than I thought! :-) It may be used for types
> holding their values not only within a specified range, but
> virtually any set (or, in other words, values conforming to any
> criterion). For instance a policy template may be written very
> easily for even numbers only. When it's used as basic_bounded's
> policy parameter, the new type will only accept even values:
>
> -------------------------------------------
>
> template<typename T>
> struct even_policy; // implementation not included for conciseness
>
> typedef basic_bounded< even_policy<int> > even_int;
> even_int i;
>
> i = 2; // OK
> i = 3; // illegal
> i += 2; // OK
> i += 3; // illegal
> i++; // illegal, might even generate a compiler error
>
> -------------------------------------------
>
> Therefore I think that this flexibility should be reflected in the
> name of the basic_bounded template as well as the library in
> general. Maybe it should be something like 'restricted' meaning that
> the types may hold only values restricted by some constraint? Or
> maybe 'constrained'? Could some native english speaker write which
> he thinks is the most appropriate name?
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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk