Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile std::regex_iterator with gcc

I can create .o file with g++ -c test.cpp -std=c++0x, but cant link it, got next errors:

test.cpp:(.text+0xe5): undefined reference to `std::regex_iterator<char const*, char, std::regex_traits<char> >::regex_iterator(char const*, char const*, std::basic_regex<char, std::regex_traits<char> > const&, std::bitset<11u>)'
test.cpp:(.text+0xf1): undefined reference to `std::regex_iterator<char const*, char, std::regex_traits<char> >::regex_iterator()'

Code:

#include <regex> 
#include <iostream> 

#include <string.h>

typedef std::regex_iterator<const char *> Myiter; 
int main() 
{ 
    const char *pat = "axayaz"; 
    Myiter::regex_type rx("a"); 
    Myiter next(pat, pat + strlen(pat), rx); 
    Myiter end; 


    return (0); 
} 
like image 739
Yola Avatar asked Dec 19 '11 13:12

Yola


People also ask

What is regex iterator in C++?

>classregex_iterator (since C++11) std::regex_iteratoris a read-only iterator that accesses the individual matches of a regular expression within the underlying character sequence. It meets the requirements of a LegacyForwardIterator, except that for dereferenceable values aand bwith a == b, *aand *bwill not be bound to the same object.

How to iterate over the same regex pattern in a sequence?

regex_iterator () is a function from the BiDirectionalIterator class in C++. This method returns an iterator type to iterate over different matches of a same regex pattern in a sequence. template< class BidirectionalIterator, class CharT = typename std::iterator_traits::value_type, class Traits = std::regex_traits > class regex_iterator

Does C++ support <regex>?

The GNU C++ standard library supports <regex>, but not until version 4.9.0. (The headers were present in earlier versions, but were unusable.) The other compilers don't support it, as far as I can see. You can use a different library if you use an older GCC. Both MSVC and Clang support <regex>.

What is the use of regex_iterator?

Conceptually, it holds a regex_iterator object that it uses to search for regular expression matches in a character sequence. It extracts objects of type sub_match<BidIt> representing the submatches identified by the index values in the stored vector subs for each regular expression match.


1 Answers

The GNU C++ standard library supports <regex>, but not until version 4.9.0. (The headers were present in earlier versions, but were unusable.)

The other compilers don't support it, as far as I can see.

You can use a different library if you use an older GCC.

like image 61
spraff Avatar answered Sep 29 '22 15:09

spraff