Boost logo

Boost :

From: Joel de Guzman (joel_at_[hidden])
Date: 2005-02-15 09:39:17


Larry Evans wrote:
> On 02/15/2005 06:47 AM, Joel de Guzman wrote:

>> Yes, it is a non-member function. No, it does not mutate s.
>> It does return another set. It is purely functional (no side-
>> effects).
>>
>> Isn't the MPL doc clear enough?
>> http://www.boost.org/libs/mpl/doc/refmanual/set.html
>>
>
> But that talks about adding a type, Tk to an mpl::set, not an instance
> of that type e, to an instance of a set.

Didn't I already explain that? Isn't it already clear that
Fusion is about functions and values while MPL is about
meta-functions and types?

> Maybe what you have in mind is that the elements are represented as
> type, integral_c<Tk, e>?

No!

> But then how could a function call (i.e.
> insert(s,k) ) work since it's arguments are instances not types?

In MPL you use metafunctions: insert<s,k>::type
In Fusion, you use plain ole functions: insert(s,k)
In MPL s and k are types.
In Fusion, s and k are values.

> Consider tuple. With tuple<T1,T2>, any operation on an instance of
> T1 or T2 you can do with tupel<T1,T2>. Likewise, I was thinking that
> since fusion::set<T1,T2> has data, there would be operations for that
> data, i.e. for instances of T1 and T2. IOW the operations would
> include adding an instance of T1 or T2 to the fusion::set just as
> with tuple<T1,T2> you have availble operations on instance of T1 or T2.

To avoid a long and winding discussion, I think it's better if you
just look at the tests. While I still do not have sets and maps
there, this sample code for push_back might be illustrative:

// Testing push_back

     {
         char const* s = "Ruby";
         typedef tuple<int, char, double, char const*> tuple_type;
         tuple_type t1(1, 'x', 3.3, s);

         {
             std::cout << push_back(t1, 123456) << std::endl;
             BOOST_TEST((push_back(t1, 123456)
                 == make_tuple(1, 'x', 3.3, s, 123456)));
         }

         {
             std::cout << push_back(t1, "funny") << std::endl;
             BOOST_TEST((push_back(t1, "funny")
                 == make_tuple(1, 'x', 3.3, s, std::string("funny"))));
         }

         {
             std::cout << push_back(t1, t1) << std::endl;
             BOOST_TEST((push_back(t1, t1)
                 == make_tuple(1, 'x', 3.3, s, t1)));
         }
     }

     {
         typedef boost::mpl::vector_c<int, 1, 2, 3, 4, 5> mpl_vec;
         std::cout << boost::fusion::push_back(
             mpl_vec(), boost::mpl::int_<6>()) << std::endl;
         BOOST_TEST((boost::fusion::push_back(
             mpl_vec(), boost::mpl::int_<6>())
             == make_tuple(1, 2, 3, 4, 5, 6)));
     }

HTH,

-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net

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