Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8643779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:08:08+00:00 2026-06-12T12:08:08+00:00

I’d like to do something like this: boost::regex re(tryme); ifstream iss; iss.open(file.txt); istream_iterator<string> eos;

  • 0

I’d like to do something like this:

boost::regex re("tryme");
ifstream iss;
iss.open("file.txt");
istream_iterator<string> eos;     
istream_iterator<string> iit (iss);

find(iit,eos,bind2nd(boost::regex_match),re));

The errors are following:

Could not find a match for ‘bind2nd<_Fn2,_Ty>(bool (*) (BidiIterator,BidiIterator,match_results &,const basic_regex &,unsigned long))’

Could not find a match for ‘find(istream_iterator,int>,istream_iterator,int>,undefined,regex)’

Could you please help me to do it correctly? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:08:09+00:00Added an answer on June 12, 2026 at 12:08 pm

    The first problem is that std::find() tries to match values, i.e., you need to replace std::find() by std::find_if(). That’s simple to do.

    The next problem is that boost::regex_match isn’t one function but a family of functions. std::bind2nd() has no idea which member of this family you want to match against. Also, the function overload you apparently want to use takes three, not two, arguments: the last argument of type boost::match_flag_type is defaulted. I got it to work with std::bind() using this:

    std::bind(static_cast<bool (*)(std::string const&,
                                   boost::regex const&,
                                   boost::match_flag_type)>(&boost::regex_match),
             std::placeholders::_1, re);
    

    If you really want to use std::bind2nd() it is probably easiest to create a simple forwarding function:

    bool my_regex_match(std::string s, boost::regex const& r) {
        return boost::regex_match(s, r);
    }
    
    void f() {
        boost::regex re("tryme");
        std::ifstream iss(file.txt);
        std::find_if(std::istream_iterator<std::string>(iss),
                 std::istream_iterator<std::string>(),
                 std::bind2nd(std::ptr_fun(&my_regex_match), re));
    }
    

    The std::bind2nd() template cannot really work with raw function pointers. This is why std::ptr_fun() needs to be used. In general, when any of the standard functions called *_fun() need to be used, the fun actually stops: these functions cannot cope with functions taking arguments by reference. Thus, my_regex_match() takes its std::string argument by value: std::bind2nd() would try to create a function object taking a reference to reference as argument otherwise. This is another reason why you might want to use std::bind() or boost::bind().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I would like to count the length of a string with PHP. The string
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.