On Mon, Aug 31, 2009 at 7:47 PM, Ryan McConnehey <mccorywork@gmail.com> wrote:
I have a mpl::map as follows, with a template parameter of a passed in type and a template parameter of "supported_type" that is a class.

using boost::mpl;
enum { value = 1 + supported_type::value };
typedef typename insert<typename supported_type::type_map, pair<T, int_<value> > >::type  type_map;

I'm trying to create a function that searches the map for a given type and returns a numeric value if it's found or -1 if it's not found.

template <typename S>  int typeValue(void)  {
 return at< type_map, S, int_<-1> >::type::value;
}

The documentation says I can specify a default value for "at" that is returned if the given key isn't found.  The compiler, though, says that I've provided too many arguments.  Have I called "at" incorrectly?  Is the documentation incorrect?  Is the fault with the compiler (VS 2005)?

Ryan

I've created a work around using the boost::enable_if and boost::disable_if  that provides the functionality I need.  I would prefer to use the mpl::at with the default argument if I can.  If someone could help me I'd appreciate it.

template <typename S> typename boost::enable_if< boost::mpl::has_key< type_map, S >, int >::type typeValue(void)  {
  return boost::mpl::at< type_map, S >::type::value;
}

template <typename S> typename boost::disable_if< boost::mpl::has_key< type_map, S >, int >::type typeValue(void)  {
  return -1;
}

Ryan