Is this correct C++ code (Boost pool allocator with "const
std::string" key)
{ reformatted; please limit your lines to 70 characters -mod }
The following code compiles under g++ 4.5.3, but does not under MS
Visual Studio 2008:
#include <map>
#include <boost/pool/pool_alloc.hpp>
int main()
{
typedef const std::string key;
typedef double* (*value)(const int&);
std::map<key, value, std::less<key>,
boost::fast_pool_allocator<std::pair<const key, value> > >
map_with_boost_allocator; // fails
}
(Boost version is 1.48). I've tracked the error to the compiler
thinking that these two lines in boost/pool/pool_allocator.hpp define
the same function:
static pointer address(reference r)
{
return &r;
}
static const_pointer address(const_reference s)
{ return &s; }
Where "reference" and "const reference" are defined as
typedef value_type & reference;
typedef const value_type & const_reference;
In this case, "value_type" is "const K" where "K" == "const
std::string". Which compiler is correct:
g++ in accepting the code or MS Visual Studio 2008 in rejecting the
code?
Regards,
Roman
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]