Boost logo

Boost :

From: Valentin Bonnard (Bonnard.V_at_[hidden])
Date: 1999-07-07 10:05:04


Beman Dawes wrote:
>
> At 02:46 PM 7/7/99 +0200, Valentin Bonnard wrote:

> >We don't need to force anyone if:
> >
> >- the trait values all have an unknown
> > special value
> >
> >- the algorithms can deal with that
> > unknown value
> >
> >Also note that third parties can provide
> >the traits for containers simply by reading
> >the documentation.
> >
> >At any rate it doesn't require any changes
> >to the containers classes !
> >
> >See
> >http://www.eleves.ens.fr:8080/home/bonnard/ContAlgo/ContTraits.hpp
> >for an _example_ (I will probably rewrite it).
>
> Is the usage to then include container_trait<whatever> as a template
> parameter for one of your algorithms?

Not as an argument to the algorithms.

> I would like to see a usage
> example.

// very useful example of the use of traits
// foobar.hpp

#include "sometrait.hpp"
// for definition of the TypeLogic namespace,
// and of sometrait

using std::cout;
using namespace boost;

void bar (unknown)
{
    cout << "color unknown\n";
}

void bar (yes)
{
    cout << "red\n";
}

void bar (no)
{
    cout << "non red\n";
}

void foo (T&)
{
    bar (boost::sometrait<T>::is_red ());
}

// user code

#include "fobar.hpp"

struct Red {};
struct Alien {};

namespace boost {
template <>
struct sometrait<Red> {
typedef yes is_red;
};
} // boost

int main ()
{
    bar (Red ());
    bar (Alien ());
}

would print

yes
unknown color

because the defalt trait used for Alien doesn't know
the color.

> I worry that algorithms on containers will be less automatically
> extensible to new containers than algorithms on iterators.

It's up to the container writer to provide the
corresponding traits. Since he may not know about
Boost, and since the ISO standard fails to mention
Valentin Bonnard's container requirements <g>, he
may provide a container class w/o the trait classes.

For standard containers, it's up to the boost header
to provide the appropriate traits.

For third party containers, the user of both boost
and the container can write a ``boost description''
of the container by reading the documentation.

In other words, it's up to the user to connect
arbitrary containers to my interface.

-- 
Valentin Bonnard
------------------------------------------------------------------------
eGroups.com home: http://www.egroups.com/group/boost
http://www.egroups.com - Simplifying group communications

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