title: Problems using a map with a bitset as a key
body: <p>I am trying to create a <code>map</code> in C++ with <code>bitset</code> as a key. However the compiler generates the following error messages</p>
  
  <pre><code>In file included from /usr/include/c++/4.6/string:50:0,
                   from /usr/include/c++/4.6/bits/locale_classes.h:42,
                   from /usr/include/c++/4.6/bits/ios_base.h:43,
                   from /usr/include/c++/4.6/ios:43,
                   from /usr/include/c++/4.6/ostream:40,
                   from /usr/include/c++/4.6/iostream:40,
                   from test2.cpp:1:
  /usr/include/c++/4.6/bits/stl_function.h: In member function ‘bool std::less&lt;_Tp&gt;::operator()(const _Tp&amp;, const _Tp&amp;) const [with _Tp = std::bitset&lt;8u&gt;]’:
  /usr/include/c++/4.6/bits/stl_map.h:452:2:   instantiated from ‘std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::mapped_type&amp; std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::operator[](const key_type&amp;) [with _Key = std::bitset&lt;8u&gt;, _Tp = int, _Compare = std::less&lt;std::bitset&lt;8u&gt; &gt;, _Alloc = std::allocator&lt;std::pair&lt;const std::bitset&lt;8u&gt;, int&gt; &gt;, std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::mapped_type = int, std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::key_type = std::bitset&lt;8u&gt;]’
  test2.cpp:22:30:   instantiated from here
  /usr/include/c++/4.6/bits/stl_function.h:236:22: error: no match for ‘operator&lt;’ in ‘__x &lt; __y’
  /usr/include/c++/4.6/bits/stl_function.h:236:22: note: candidates are:
  /usr/include/c++/4.6/bits/stl_pair.h:207:5: note: template&lt;class _T1, class _T2&gt; bool std::operator&lt;(const std::pair&lt;_T1, _T2&gt;&amp;, const std::pair&lt;_T1, _T2&gt;&amp;)
  /usr/include/c++/4.6/bits/stl_iterator.h:291:5: note: template&lt;class _Iterator&gt; bool std::operator&lt;(const std::reverse_iterator&lt;_Iterator&gt;&amp;, const std::reverse_iterator&lt;_Iterator&gt;&amp;)
  /usr/include/c++/4.6/bits/stl_iterator.h:341:5: note: template&lt;class _IteratorL, class _IteratorR&gt; bool std::operator&lt;(const std::reverse_iterator&lt;_IteratorL&gt;&amp;, const std::reverse_iterator&lt;_IteratorR&gt;&amp;)
  /usr/include/c++/4.6/bits/basic_string.h:2510:5: note: template&lt;class _CharT, class _Traits, class _Alloc&gt; bool std::operator&lt;(const std::basic_string&lt;_CharT, _Traits, _Alloc&gt;&amp;, const std::basic_string&lt;_CharT, _Traits, _Alloc&gt;&amp;)
  /usr/include/c++/4.6/bits/basic_string.h:2522:5: note: template&lt;class _CharT, class _Traits, class _Alloc&gt; bool std::operator&lt;(const std::basic_string&lt;_CharT, _Traits, _Alloc&gt;&amp;, const _CharT*)
  /usr/include/c++/4.6/bits/basic_string.h:2534:5: note: template&lt;class _CharT, class _Traits, class _Alloc&gt; bool std::operator&lt;(const _CharT*, const std::basic_string&lt;_CharT, _Traits, _Alloc&gt;&amp;)
  /usr/include/c++/4.6/bits/stl_tree.h:856:5: note: template&lt;class _Key, class _Val, class _KeyOfValue, class _Compare, class _Alloc&gt; bool std::operator&lt;(const std::_Rb_tree&lt;_Key, _Val, _KeyOfValue, _Compare, _Alloc&gt;&amp;, const std::_Rb_tree&lt;_Key, _Val, _KeyOfValue, _Compare, _Alloc&gt;&amp;)
  /usr/include/c++/4.6/bits/stl_set.h:713:5: note: template&lt;class _Key, class _Compare, class _Alloc&gt; bool std::operator&lt;(const std::set&lt;_Key, _Compare, _Alloc&gt;&amp;, const std::set&lt;_Key, _Compare, _Alloc&gt;&amp;)
  /usr/include/c++/4.6/bits/stl_multiset.h:696:5: note: template&lt;class _Key, class _Compare, class _Alloc&gt; bool std::operator&lt;(const std::multiset&lt;_Key, _Compare, _Alloc&gt;&amp;, const std::multiset&lt;_Key, _Compare, _Alloc&gt;&amp;)
  /usr/include/c++/4.6/bits/stl_map.h:894:5: note: template&lt;class _Key, class _Tp, class _Compare, class _Alloc&gt; bool std::operator&lt;(const std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;&amp;, const std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;&amp;)
  /usr/include/c++/4.6/bits/stl_multimap.h:812:5: note: template&lt;class _Key, class _Tp, class _Compare, class _Alloc&gt; bool std::operator&lt;(const std::multimap&lt;_Key, _Tp, _Compare, _Alloc&gt;&amp;, const std::multimap&lt;_Key, _Tp, _Compare, _Alloc&gt;&amp;)
  </code></pre>
  
  <p>The progam code is given below
  I am trying to use bitset as a key to a map in C++. However, everytime I run the code below I run into errros.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  #include &lt;string&gt;
  #include &lt;bitset&gt;
  #include &lt;set&gt;
  #include &lt;utility&gt;
  
  using namespace std;
  
  int main(int argc, char *argv[])
  {
      bitset&lt;8&gt; test;
      test = 9;
      cout&lt;&lt;"Set to 9"&lt;&lt;endl;
      map &lt;bitset&lt;8&gt; , int&gt; mymap;
      pair &lt;biset&lt;8&gt; , int&gt; p;
      p.first = test;
      p.second = 9;
      string teststring;
      teststring = test.to_string&lt;char,char_traits&lt;char&gt;,allocator&lt;char&gt; &gt;();
      cout&lt;&lt;teststring&lt;&lt;temymap[test]&lt;&lt;endl;
      return 0;
  }
  </code></pre>