Boost logo

Boost :

From: Beman Dawes (beman_at_[hidden])
Date: 1999-07-07 12:45:13


At 05:05 PM 7/7/99 +0200, Valentin Bonnard wrote:

>// very useful example of the use of traits

Valentin, you lost me. Did you mean for the definition of foo to be
preceded by template<class T>? And isn't bar(Red()); etc, supposed
to be foo(Red()); etc? I guess #include "fobar.hpp" is supposed to be
#include "foobar.hpp" Plus you better include the source for
sometrait.hpp. Sorry to be old-fashioned, but I would actually like
to compile and run your example to make sure I understand it.

--Beman

>// 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
>
>---------------------------------------------------------------------

---
>FreeShop is the #1 place for free and trial offers and great deals!
>Try something new and find out how you could win two round-trip
tickets       
>anywhere in the U.S.! http://clickhere.egroups.com/click/368
>
>
>eGroups.com home: http://www.egroups.com/group/boost
>http://www.egroups.com - Simplifying group communications
>
>
>
>
>
>
------------------------------------------------------------------------
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