Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7932975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:11:00+00:00 2026-06-03T21:11:00+00:00

Is this a Boost bug or am I doing something wrong? #include <map> #include

  • 0

Is this a Boost bug or am I doing something wrong?

#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>> map_with_standard_allocator; // works
    std::map<key, value, std::less<key>, boost::fast_pool_allocator<std::pair<const key, value> > > map_with_boost_allocator; // fails
}

the last line fails to compile under MS Visual Studio 2008 with Boost 1.40 and 1.48. It compiles fine under g++ 4.5.3 (Cygwin), though.

The error is:

1>Compiling...
1>main.cpp
1>C:\UniLib1\trunk\External\boost/pool/pool_alloc.hpp(205) : error C2535: 'const std::basic_string<_Elem,_Traits,_Ax> *boost::fast_pool_allocator<T,UserAllocator,Mutex,NextSize>::address(const std::basic_string<_Elem,_Traits,_Ax> &)' : member function already defined or declared
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>,
1>            _Ax=std::allocator<char>,
1>            T=const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,
1>            UserAllocator=boost::default_user_allocator_new_delete,
1>            Mutex=boost::details::pool::default_mutex,
1>            NextSize=32
1>        ]
1>        C:\UniLib1\trunk\External\boost/pool/pool_alloc.hpp(202) : see declaration of 'boost::fast_pool_allocator<T,UserAllocator,Mutex,NextSize>::address'
1>        with
1>        [
1>            T=const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,
1>            UserAllocator=boost::default_user_allocator_new_delete,
1>            Mutex=boost::details::pool::default_mutex,
1>            NextSize=32
1>        ]
1>        c:\Program Files\Microsoft Visual Studio 9.0\VC\include\xtree(137) : see reference to class template instantiation 'boost::fast_pool_allocator<T,UserAllocator,Mutex,NextSize>' being compiled
1>        with
1>        [
1>            T=const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,
1>            UserAllocator=boost::default_user_allocator_new_delete,
1>            Mutex=boost::details::pool::default_mutex,
1>            NextSize=32
1>        ]
1>        c:\Program Files\Microsoft Visual Studio 9.0\VC\include\map(78) : see reference to class template instantiation 'std::_Tree<_Traits>' being compiled
1>        with
1>        [
1>            _Traits=std::_Tmap_traits<key,value ,std::less<key>,boost::fast_pool_allocator<std::pair<key,value >>,false>
1>        ]
1>        .\main.cpp(9) : see reference to class template instantiation 'std::map<_Kty,_Ty,_Pr,_Alloc>' being compiled
1>        with
1>        [
1>            _Kty=key,
1>            _Ty=value,
1>            _Pr=std::less<key>,
1>            _Alloc=boost::fast_pool_allocator<std::pair<key,value >>
1>        ]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T21:11:02+00:00Added an answer on June 3, 2026 at 9:11 pm

    This is not a bug in VS2008 (as I mistakenly claimed in an earlier edit to this answer). The C++03 standard requires that the key type for an associative container, like std::map, must be ‘assignable’ (per Table 69 in 23.1.2 “Associative containers”). And a const std::string is not assignable. Note that the C++11 standard seems to relax this requirement, but the new standard doesn’t apply to since VC++ 2008.

    It’s not clear to me that a compiler is required to diagnose code that tries to use std::map with a non-assignable key, so I don’t think one can claim that GCC or VC++ 2010 are accepting this code improperly (I think it falls into the area of undefined code that works as you might expect, even though there’s no guarantee it’ll work). However it is clear that it’s OK for VC++ 2008 to refuse to compile it.

    All that said, I think that VC++ 2008’s library parameterizing the allocator’s address() function on the map’s key rather than map’s element is still suspect (see the first edit of this answer for details if you’re interested), but I don’t think there’s any real bug there since the std::pair<> used to hold the map element will always be set up such that key part will be at the same address as the whole element.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the code snippet: #include <boost/utility.hpp> #include <boost/type_traits.hpp> #include <boost/type_traits/is_base_of.hpp> #include <boost/typeof/typeof.hpp> enum
I have this simple piece of code that uses boost::bind: #include <boost/bind.hpp> #include <utility>
when I try to compile this code: #include <boost/filesystem/path.hpp> #include <boost/filesystem/fstream.hpp> using namespace std;
In boost 1.48.0 I find this in the regex code (boost/regex/v4/ w32_regex_traits.hpp ): w32_regex_traits()
Trying to build the following simple example #include <boost/python.hpp> using namespace boost::python; tuple head_and_tail(object
The following noddy test code: #include <iostream> #include <list> #include <boost/any.hpp> #include <boost/foreach.hpp> #include
Consider: template < typename Something > boost::function<void()> f() { typedef typename Something::what type; return
Why is this boost::lambda expression not working? boost::function<bool (boost::uint64_t, boost::uint64_t&, unsigned int, float)> myFunct
I implemented the following GBDM example: #include <boost/lexical_cast.hpp> #include <gdbm.h> #include <iostream> #include <string>
I am doing this boost::gregorian::date current_date(boost::date_time::day_clock::local_day()); and I get the following error ‘template<class date_type>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.