Boost logo

Boost :

Subject: [boost] [unordered] unordered_map forces non-const version of automatic assignment operator
From: STEAG Energy Services GmbH (Tobias.Loew_at_[hidden])
Date: 2011-11-23 11:39:38


Hi,

I just switched from boost version 1.47 to 1.48 and now I've got the effect that my compiler (msvc 2008) generates the wrong (i.e. non-const) assignment operator in the following example:

///////////////////////////////////////////////////////////////////
struct copy_test
{
public:
//#define USER_ASSIGN
#ifdef USER_ASSIGN
    copy_test & operator = (const copy_test & other)
    {
        map = other.map;
        return *this;
    }
#endif
    boost::unordered_map<std::wstring,std::wstring> map;
};

void foo()
{
    copy_test a,b;
    const copy_test c;
    a=b;
    a=c; // error if USER_ASSIGN is not defined
}

////////////////////////////////////////////////////////////

I think the reason is use of BOOST_COPY_ASSIGN_REF in unordered_map.hpp:148, as it expands the assignment operator to

unordered_map& operator=(const ::boost::rv<unordered_map>& x)

I think the same problems arise on other compilers without rv-references and containers that use BOOST_COPY_ASSIGN_REF.

regards

Tobias


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