Boost logo

Boost :

From: helmut.zeisel_at_[hidden]
Date: 2001-08-27 07:28:27


--- In boost_at_y..., "Peter Dimov" <pdimov_at_m...> wrote:
> From: <helmut.zeisel_at_a...>
> > --- In boost_at_y..., "Peter Dimov" <pdimov_at_m...> wrote:
> > > template<class Tag, class A> struct extensible_traits;
> > >
> > > struct is_even_tag {};
> > >
> > > template<class Int> struct extensible_traits<is_even_tag, Int>
> > > {
> > > typedef bool result_type;
> > > static result_type f(Int i) { return i % 2 == 0; }
> > > };
> > >
> >
> > Do I understand correctly:
> >
> > Implementation of is_even:
> >
> > template<typename T> bool is_even(const T& n)
> > {
> > return extensible_traits<is_even_tag,T>::f();
> > };
> >
> > Usage:
> >
> > int n;
> > ...
> > if(is_even(n)) {...}
>
> Yes, that's it.

I like these extensible_traits.

There is, however, one problem:

I see two reasonable default implementations for is_even
(and for many other similar functions):

i %2 == 0 // for built-in types

and

i.is_even(); // for most user defined types

In my (less extensible) version I could provide
both versions easily:
by a "default_tag" and a "member_tag"

Is there a possibility in your approach
to provide a small number of alternatives
in a cheap way?

I think, before we can find a generally accepted
interface for an unlimited interface class,
it might be helpful to have a collection
of such, say, "general purpose template functions / traits."
(This might influence the decision whether we
need conversion to built-in types or not).

I can provide a sample implementation with
the next version of my big_int class;
at the moment, however, it is not clear to
me which implementation of this
general purpose templates/traits
would be the most suitable.

Helmut


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