|
Boost : |
From: helmut.zeisel_at_[hidden]
Date: 2001-08-24 15:28:59
--- In boost_at_y..., scleary_at_j... wrote:
> > > > Would there be some need for seminumerical functions?
> > > > Would this solution be better than
> > > > an implicit conversion to bool for unlimited integer?
> > >
> > > I think it's a better solution. I also think there's a place
for
> > > numeric/integer traits which would support generic
numeric/integer
> > > algorithms.
> > >
> >
> > Can yo be a bit more specific what kind of traits you
> > are thinking of?
>
> I don't mean just type properties (e.g., is_bounded/is_signed), but
also
> type methods (int_traits is a namespace):
> int_traits::is_zero(x) -- returns true if x == 0
> int_traits::is_positive(x) -- returns true if x >= 0
> int_traits::is_odd(x) -- returns true if (x % 2) == 1
>
I do net yet understand completely what you mean.
I was thinking in the way
struct default_tag {};
struct member_tag{};
template<typename T> struct seminumerical_traits
{
typedef default_tag is_zero_tag;
typedef default_tag is_positive_tag;
typedef default_tag is_odd_tag;
...
};
// Specialistaion
template<> struct seminumerical_traits<unlimited>
{
typedef member_tag is_zero_tag;
typedef member_tag is_positive_tag;
typedef member_tag is_odd_tag;
...
};
// General interface
template<typename T> bool is_zero(const T& t)
{
return is_zero(t, typename T::is_zero_tag());
}
// Implementation for built-in
template<typename T> bool is_zero(const T& t, default_tag)
{
return t==0;
}
// Possible implementation for user defined types
template<typename T> bool is_zero(const T& t, member_tag)
{
return t.is_zero();
}
Is this what you meant?
Gabriel Dos Reis suggested an alternative implementation
technique in http://groups.yahoo.com/group/boost/message/15866,
but I still have not yet understood completely
how that should work.
Helmut
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk