Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

algorithm/string -- find_all_regex() gives a compiler error when the result container is vector<iterator_range<string::iterator>> #87

Open
Oshanath opened this issue Sep 27, 2021 · 0 comments

Comments

@Oshanath
Copy link

Oshanath commented Sep 27, 2021

The doc says that the container we should pass to this function can be std::vector<boost::iterator_rangestd::string::iterator>. But when I run the program it gives a compile error. But when the result container passed, is a std::vectorstd::string, everything works fine.

First code snippet is using std::vector<boost::iterator_rangestd::string::iterator> as the result.

#include "boost/algorithm/string/split.hpp"
#include "boost/range/iterator_range_core.hpp"
#include <iostream>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/regex.hpp>
#include <vector>

int main(int, char**) {
    
    std::string s("Hello world");
    boost::regex regex("\\w");

    std::vector<boost::iterator_range<std::string::iterator>> result;
    boost::find_all_regex(result, s, regex);

}

Following is the last 3 lines of the compiler error. The whole error is too long.

c:\mingw\include\c++\9.2.0\bits\stl_iterator.h:787:11: note: no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string >' to 'const __gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string >&'

c:\mingw\include\c++\9.2.0\bits\stl_iterator.h:787:11: note: candidate: 'constexpr __gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string >::__normal_iterator(__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string >&&)'

c:\mingw\include\c++\9.2.0\bits\stl_iterator.h:787:11: note: no known conversion for argument 1 from '__gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string >' to '__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string >&&'

Also I ran the same program in Clang compiler too. Still the same result.

But when I run the following program with the container as std::vectorstd::string everything works without a hitch.

#include "boost/algorithm/string/split.hpp"
#include "boost/range/iterator_range_core.hpp"
#include <iostream>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/regex.hpp>
#include <string>
#include <vector>

int main(int, char**) {
    
    std::string s("Hello world");
    boost::regex regex("\\w");

    std::vector<std::string> result;
    boost::find_all_regex(result, s, regex);

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant