$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-users] workaround ideas?
From: Noah Roberts (roberts.noah_at_[hidden])
Date: 2009-03-03 11:59:51
This may be a little OT but as it applies to metaprogramming and ideas 
from the book I thought it the best place to ask.
On pgs 191/2 of the MPL book (section 9.5) is a set of ideas meant to 
introduce the inherit_linearly metafunction.  There are some things I 
want to do that suggested this was actually the better way to go for me. 
  So I implemented something like the following:
struct empty {};
template < typename FIELD, typename CDR >
struct rec : CDR
{
   typename FIELD::type value;
   rec() : value() {}
};
template < typename VEC >
struct generate_record
   //: boost::mpl::inherit_linearly< VEC, boost::mpl::inherit< 
rec<pl::_2>, pl::_1> >::type
   : boost::mpl::fold< VEC, empty, rec< pl::_2, pl::_1> >
{};
I implemented a getter function like so:
template < typename FIELD, typename CDR >
typename FIELD::type & get(rec< FIELD, CDR > & r)
{
   return r.value;
}
Now, minus the "field" concept this seems to be exactly the same basic 
thing.  The field concept is something I need for what I'm working on 
that currently, for this test, just has a type in it.
I create a "record" like so:
typedef generate_record< boost::mpl::vector<field1, field2, field3> 
 >::type test_record;
When I print the type I end up with:
"rec<field3,rec<field2,rec<field1,empty> > >"
and in main attempt to access it:
   test_record tr;
   get<field1>(tr) = 3;
This works fine in comeau and I'd expect it to work anywhere but MSVC++ 
8 doesn't like it.  It says that the FIELD param is ambiguous and could 
be field1 (what I specified in the call) or field3 (the first field on 
the inheritance tree).  The error text is exactly:
1>e:\dev_workspace\experimental\record_generation\record_generation\main.cpp(78) 
: error C2782: 'FIELD::type &get(rec<FIELD,CDR> &)' : template parameter 
'FIELD' is ambiguous
1> 
e:\dev_workspace\experimental\record_generation\record_generation\main.cpp(58) 
: see declaration of 'get'
1>        could be 'field3'
1>        or 'field1'
I'm calling this a compiler bug at this point.  I suspect many here have 
had to deal with this, since it's basic template usage, and might know a 
workaround.  Or maybe you see something I've done incorrectly.