Boost logo

Boost Users :

From: Josue Gomes (josue_at_[hidden])
Date: 2005-02-24 06:30:10


Hi,

Take this code:

#include <boost/assign/std.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/assign/list_inserter.hpp>

#include <map>
#include <iostream>
#include <string>

using namespace std;
using namespace boost::assign;

const unsigned long USER = 0x0001;
const unsigned long ADMINISTRATOR = 0x0004;

const unsigned long ALL = USER + ADMINISTRATOR;

typedef map<string, long> item_permissions_t;
typedef map<string, item_permissions_t> module_permissions_t;

int main()
{
  map<string, module_permissions_t> permission_table = map_list_of
    ("Module1", map_list_of
      ("Item1", map_list_of
        ("Feature1", ALL)
        ("Feature2", ADMINISTRATOR)
      )
      ("Item2", map_list_of
        ("Feature1", ALL)
        ("Feature2", ALL)
        ("Feature3", ADMINISTRATOR)
        ("Feature4", ADMINISTRATOR)
      )
    );

  cout << "modules: " << permission_table.size() << "\n";
  cout << "items of module 'Module1': " <<
        permission_table["Module1"].size() << "\n";
  cout << "features of item 'Item2' of module 'Module1': " <<
        permission_table["Module1"]["Item2"].size() << "\n";
  cout << "permissions of feature 'Feature4' of item 'Item2' of "
        "module 'Module1': " <<
        permission_table["Module1"]["Item2"]["Feature4"] << "\n";
}

It compiles fine with VC 7.1. However g++ 3.3 and 3.4
(both on Linux) refuse to compile it.

See the error message (excerpt):

sample.cpp:36: instantiated from here
/usr/include/c++/3.4/bits/stl_pair.h:90: error: call of overloaded
`map(const boost::assign_detail::generic_list<std::pair<const char*,
boost::assign_detail::generic_list<std::pair<const char*, long unsigned
int> > > >&)' is ambiguous
/usr/include/c++/3.4/bits/stl_map.h:166: note: candidates are:
std::map<_Key, _Tp, _Compare, _Alloc>::map(const std::map<_Key, _Tp,
_Compare, _Alloc>&) [with _Key = std::string, _Tp = item_permissions_t,
_Compare = std::less<std::string>, _Alloc = std::allocator<std::pair<const
std::string, item_permissions_t> >]
/usr/include/c++/3.4/bits/stl_map.h:156: note:
std::map<_Key, _Tp, _Compare, _Alloc>::map(const _Compare&, const typename
std::_Rb_tree<_Key, std::pair<const _Key, _Tp>,
std::_Select1st<std::pair<const _Key, _Tp> >, _Compare,
_Alloc>::allocator_type&) [with _Key = std::string, _Tp =
item_permissions_t, _Compare = std::less<std::string>, _Alloc =
std::allocator<std::pair<const std::string, item_permissions_t> >]

the command line is:

g++-3.4 -I ../boost_1_32_0/ sample.cpp -o sample

Any ideas of what is going on here?

Regards,
Josue Gomes


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