title: trouble compiling a program using boost regex library
body: <p>I tried to compile a boost program which was using boost regex library on my linux box. it has all the required headers and libraries. The program refuses to compile throwing a huge dump of template output. 
  I am using the following command to compile the program. </p>
  
  <p>pls advise on how to fix the below. </p>
  
  <p><strong>g++  regex.cc -I/usr/local/include/boost/  -L/usr/local/lib -lboost_regex  -o regex</strong></p>
  
  <p>here is the output of the compiler. </p>
  
  <pre><code>ravit@ravit-laptop:~$ g++  regex.cc -I/usr/local/include/boost/  -L/usr/local/lib -lboost_regex  -o regex 
  In file included from /usr/local/include/boost/regex/v4/perl_matcher.hpp:582,
                   from /usr/local/include/boost/regex/v4/regex.hpp:88,
                   from /usr/local/include/boost/regex.hpp:31,
                   from regex.cc:19:
  /usr/local/include/boost/regex/v4/perl_matcher_common.hpp: In member function ‘bool boost::re_detail::perl_matcher&lt;BidiIterator, Allocator, traits&gt;::match_assert_backref() [with BidiIterator = __gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, Allocator = std::allocator&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;, traits = boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt;]’:
  /usr/local/include/boost/regex/v4/perl_matcher_non_recursive.hpp:180:   instantiated from ‘bool boost::re_detail::perl_matcher&lt;BidiIterator, Allocator, traits&gt;::match_all_states() [with BidiIterator = __gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, Allocator = std::allocator&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;, traits = boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt;]’
  /usr/local/include/boost/regex/v4/perl_matcher_common.hpp:323:   instantiated from ‘bool boost::re_detail::perl_matcher&lt;BidiIterator, Allocator, traits&gt;::match_prefix() [with BidiIterator = __gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, Allocator = std::allocator&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;, traits = boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt;]’
  /usr/local/include/boost/regex/v4/perl_matcher_common.hpp:207:   instantiated from ‘bool boost::re_detail::perl_matcher&lt;BidiIterator, Allocator, traits&gt;::match_imp() [with BidiIterator = __gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, Allocator = std::allocator&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;, traits = boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt;]’
  /usr/local/include/boost/regex/v4/perl_matcher_common.hpp:180:   instantiated from ‘bool boost::re_detail::perl_matcher&lt;BidiIterator, Allocator, traits&gt;::match() [with BidiIterator = __gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, Allocator = std::allocator&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;, traits = boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt;]’
  /usr/local/include/boost/regex/v4/regex_match.hpp:50:   instantiated from ‘bool boost::regex_match(BidiIterator, BidiIterator, boost::match_results&lt;Iterator, Allocator&gt;&amp;, const boost::basic_regex&lt;charT, traits&gt;&amp;, boost::regex_constants::match_flag_type) [with BidiIterator = __gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, Allocator = std::allocator&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;, charT = char, traits = boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt;]’
  /usr/local/include/boost/regex/v4/regex_match.hpp:82:   instantiated from ‘bool boost::regex_match(const std::basic_string&lt;charT, ST, SA&gt;&amp;, boost::match_results&lt;typename std::basic_string&lt;charT, ST, SA&gt;::const_iterator, Allocator&gt;&amp;, const boost::basic_regex&lt;charT, traits&gt;&amp;, boost::regex_constants::match_flag_type) [with ST = std::char_traits&lt;char&gt;, SA = std::allocator&lt;char&gt;, Allocator = std::allocator&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;, charT = char, traits = boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt;]’
  regex.cc:30:   instantiated from here
  /usr/local/include/boost/regex/v4/perl_matcher_common.hpp:768: error: request for member ‘back’ in ‘((boost::re_detail::perl_matcher&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt;*)this)-&gt;boost::re_detail::perl_matcher&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt;::recursion_stack’, which is of non-class type ‘boost::re_detail::recursion_info&lt;boost::match_results&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt; &gt; &gt; [50]’
  /usr/local/include/boost/regex/v4/perl_matcher_common.hpp:768: error: request for member ‘empty’ in ‘((boost::re_detail::perl_matcher&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt;*)this)-&gt;boost::re_detail::perl_matcher&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt;::recursion_stack’, which is of non-class type ‘boost::re_detail::recursion_info&lt;boost::match_results&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt; &gt; &gt; [50]’
  /usr/local/include/boost/regex/v4/perl_matcher_common.hpp:778: error: request for member ‘back’ in ‘((boost::re_detail::perl_matcher&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt;*)this)-&gt;boost::re_detail::perl_matcher&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt;::recursion_stack’, which is of non-class type ‘boost::re_detail::recursion_info&lt;boost::match_results&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt; &gt; &gt; [50]’
  /usr/local/include/boost/regex/v4/perl_matcher_common.hpp:778: error: request for member ‘empty’ in ‘((boost::re_detail::perl_matcher&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt;*)this)-&gt;boost::re_detail::perl_matcher&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;, boost::regex_traits&lt;char, boost::cpp_regex_traits&lt;char&gt; &gt; &gt;::recursion_stack’, which is of non-class type ‘boost::re_detail::recursion_info&lt;boost::match_results&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;, std::allocator&lt;boost::sub_match&lt;__gnu_cxx::__normal_iterator&lt;const char*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt; &gt; &gt; [50]’
  </code></pre>
  
  <p>here is the piece of code taken from the same boost regex documentation </p>
  
  <pre><code>#include &lt;boost/regex.hpp&gt;
  #include &lt;iostream&gt;
  
  void
  print_captures(const std::string&amp; regx,
                 const std::string&amp; text)
  {
     boost::regex e(regx);
     boost::smatch what;
     std::cout &lt;&lt; "Expression:  \"" &lt;&lt; regx &lt;&lt; "\"\n";
     std::cout &lt;&lt; "Text:        \"" &lt;&lt; text &lt;&lt; "\"\n";
     if(boost::regex_match(text, what, e, boost::match_extra))
     {
        unsigned i, j;
        std::cout &lt;&lt; "** Match found **\n   Sub-Expressions:\n";
        for(i = 0; i &lt; what.size(); ++i)
           std::cout &lt;&lt; "      $" &lt;&lt; i &lt;&lt; " = \"" &lt;&lt; what[i] &lt;&lt; "\"\n";
        std::cout &lt;&lt; "   Captures:\n";
        for(i = 0; i &lt; what.size(); ++i)
        {
           std::cout &lt;&lt; "      $" &lt;&lt; i &lt;&lt; " = {";
           for(j = 0; j &lt; what.captures(i).size(); ++j)
           {
              if(j)
                 std::cout &lt;&lt; ", ";
              else
                 std::cout &lt;&lt; " ";
              std::cout &lt;&lt; "\"" &lt;&lt; what.captures(i)[j] &lt;&lt; "\"";
           }
           std::cout &lt;&lt; " }\n";
        }
     }
     else
        std::cout &lt;&lt; "** No Match found **\n";
  }
  
  int main(int , char* [])
  {
     print_captures("(([[:lower:]]+)|([[:upper:]]+))+", "aBBcccDDDDDeeeeeeee");
     print_captures("a(b+|((c)*))+d", "abd");
     print_captures("(.*)bar|(.*)bah", "abcbar");
     print_captures("(.*)bar|(.*)bah", "abcbah");
     print_captures("^(?:(\\w+)|(?&gt;\\W+))*$", "now is the time for all good men to come to the aid of the party");
     print_captures("^(?&gt;(\\w+)\\W*)*$", "now is the time for all good men to come to the aid of the party");
     print_captures("^(\\w+)\\W+(?&gt;(\\w+)\\W+)*(\\w+)$", "now is the time for all good men to come to the aid of the party");
     print_captures("^(\\w+)\\W+(?&gt;(\\w+)\\W+(?:(\\w+)\\W+){0,2})*(\\w+)$", "now is the time for all good men to come to the aid of the party");
     return 0;
  }
  </code></pre>