title: Populating the std::map of boost::function with boost::assign::map_list_of
body: <p>I would like to create a key-value data structure that would be useful for responding to the events of string matching to regex patterns. So I am trying to work it out with a Boost library:</p>
  
  <pre><code>#include &lt;boost/regex.hpp&gt;
  #include &lt;boost/function.hpp&gt;
  #include &lt;boost/bind.hpp&gt;
  #include &lt;boost/assign.hpp&gt;
  #include &lt;map&gt;
  
  typedef std::map&lt;boost::regex, boost::function&lt;void(void)&gt; &gt; regex_callback;
  
  void SuOpenedCallback()
  {
  }
  
  void SuClosedCallback()
  {
  }
  
  
  int main(int argc, char** argv)
  {
      //Don't pay attention to these definitions... 
      boost::regex su_opened  ("^(\\w+)\\s(\\d+)\\s([\\d:]+)\\s(\\w+)\\s"
                              "su: pam_unix\\(su:session\\): session opened for user{1}\\s([\\w\\d]+)\\sby{1}\\s([\\w\\d]+)\\(uid=([\\d]+)\\)$"); 
      boost::regex su_closed  ("^(\\w+)\\s(\\d+)\\s([\\d:]+)\\s(\\w+)\\s"
                              "su: pam_unix\\(su:session\\): session closed for user{1}\\s([\\w\\d]+)$");
  
      //Compilation error:
      regex_callback resolver = boost::assign::map_list_of&lt;boost::regex, boost::function&lt;void(void)&gt; &gt;
          (su_opened, boost::bind(&amp;SuOpenedCallback))
          (su_closed, boost::bind(&amp;SuClosedCallback));
  
  //...
  
  }
  </code></pre>
  
  <p>When I try to compile it (unfortunately I am forced to use quite old software - gcc 4.4.7, boost 1.41, therefore C++11 support is very limited):</p>
  
  <pre><code> g++ boost_regexp.cpp -o test -lboost_regex -std=c++0x
  </code></pre>
  
  <p>compilation fails with this error:</p>
  
  <blockquote>
    <p><code>boost_regexp.cpp: In function ‘int main(int, char**)’:
    boost_regexp.cpp:58: error: ambiguous overload for ‘operator=’ in
    ‘resolver = boost::assign::map_list_of(const Key&amp;, const T&amp;) [with Key
    = boost::regex, T = boost::_bi::bind_t&lt;void, void (*)(), boost::_bi::list0&gt;](((const boost::_bi::bind_t&lt;void, void (*)(),
    boost::_bi::list0&gt;&amp;)((const boost::_bi::bind_t&lt;void, void (*)(),
    boost::_bi::list0&gt;*)(&amp; boost::bind [with R =
    void](SuOpenedCallback))))).boost::assign_detail::generic_list&lt;T&gt;::operator()
    [with U = boost::regex, U0 = boost::_bi::bind_t&lt;void, void (*)(),
    boost::_bi::list0&gt;, T = std::pair&lt;boost::basic_regex&lt;char,
    boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt;,
    boost::_bi::bind_t&lt;void, void (*)(), boost::_bi::list0&gt;](((const
    boost::regex&amp;)((const boost::regex*)(&amp; su_closed))), ((const
    boost::_bi::bind_t&lt;void, void (*)(), boost::_bi::list0&gt;&amp;)((const
    boost::_bi::bind_t&lt;void, void (*)(), boost::_bi::list0&gt;*)(&amp;
    boost::bind [with R = void](SuClosedCallback)))))’
    /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_map.h:251:
    note: candidates are: std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;&amp;
    std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::operator=(const std::map&lt;_Key,
    _Tp, _Compare, _Alloc&gt;&amp;) [with _Key = boost::basic_regex&lt;char, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt;, _Tp =
    boost::function&lt;void()&gt;, _Compare = std::less&lt;boost::basic_regex&lt;char,
    boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt;, _Alloc
    = std::allocator&lt;std::pair&lt;const boost::basic_regex&lt;char, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt;,
    boost::function&lt;void()&gt;]
    /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_map.h:266:
    note:                 std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;&amp;
    std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::operator=(std::map&lt;_Key, _Tp,
    _Compare, _Alloc&gt;&amp;&amp;) [with _Key = boost::basic_regex&lt;char, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt;, _Tp =
    boost::function&lt;void()&gt;, _Compare = std::less&lt;boost::basic_regex&lt;char,
    boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt;, _Alloc
    = std::allocator&lt;std::pair&lt;const boost::basic_regex&lt;char, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt;,
    boost::function&lt;void()&gt;]
    /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_map.h:286:
    note:                 std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;&amp;
    std::map&lt;_Key, _Tp, _Compare,
    _Alloc&gt;::operator=(std::initializer_list&lt;std::pair&lt;const _Key, _Tp&gt;) [with _Key = boost::basic_regex&lt;char, boost::regex_traits&lt;char,
    boost::cpp_regex_traits&lt;char&gt;, _Tp = boost::function&lt;void()&gt;,
    _Compare = std::less&lt;boost::basic_regex&lt;char, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt;, _Alloc
    = std::allocator&lt;std::pair&lt;const boost::basic_regex&lt;char, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt;,
    boost::function&lt;void()&gt;] make: *** [all] Error 1</code></p>
  </blockquote>
  
  <p>Seems like my problem is close to <a href="https://stackoverflow.com/questions/13125924/using-boostassign-with-a-stdset-nested-inside-a-stdmap">this one</a>, however, it does not inspire me. It would be nice if someone could show me the mistake. </p>
  
  <p><strong>ANSWER</strong> As @sehe has mentioned, this code is correct for up-to-date versions of gcc but cannot be handled with gcc 4.4. Unfortunately for me. </p>