Boost logo

Boost Users :

From: Scott Meyers (usenet_at_[hidden])
Date: 2007-03-28 18:27:56


In my continuing effort to demonstrate my inability to get much of anything
working with the MPL, I'm having trouble inserting a type into an existing set
of types. The code compiles and runs, but the revised type sequence is empty.
Here's the code:

#include <boost/mpl/set.hpp>
#include <boost/mpl/for_each.hpp>
#include <typeinfo>
#include <iostream>

namespace mpl = boost::mpl;

struct Base { virtual ~Base(){} };
struct A { virtual ~A(){} };
struct B { virtual ~B(){} };

struct Print {
   template<typename T>
   void operator()(const T&)
   {
     std::cout << typeid(T).name() << ", ";
   }
};

int main()
{
   typedef mpl::set<A, B> Constraints;

   // print contents of Constraints (should be the equivalent
   // of "[A, B,]")
   std::cout << '[';
   mpl::for_each<Constraints>(Print());
   std::cout << "]\n";

   // add Base to Constraints, call result BaseClasses
   typedef mpl::insert<Constraints,
                       mpl::end<Constraints>,
                       Base> BaseClasses;

   // print contents of BaseClasses (should be the equivalent
   // of "[A, B, Base, ]")
   std::cout << '[';
   mpl::for_each<BaseClasses>(Print());
   std::cout << "]\n";
}

Can anybody spot what I'm doing wrong? I know that I could use the two-argument
form of insert with a set, but I'm trying to write code that will work with a
vector, too, and at any rate, I get the same results with the two-argument form
of set.

Thanks,

Scott


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net