Boost logo

Boost :

From: helmut.zeisel_at_[hidden]
Date: 2001-08-26 06:29:39


--- In boost_at_y..., "Peter Dimov" <pdimov_at_m...> wrote:
> From: <scleary_at_j...>
> > Hmm. I don't see a really good solution from either of these.
This
> > is just an explanation of the problem, as I see it: how can we
> > provide a 'traits' concept that allows the adding of user traits?
>
> 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)) {...}

Why do you need result_type?

Helmut


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