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 8644793
In Process

The Archive Base Latest Questions

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

I am trying to use boost::trim on a vector of strings. I understand that

  • 0

I am trying to use boost::trim on a vector of strings. I understand that this solutions works elegantly, however I cannot understand why

std::for_each(df.colnames.begin(), df.colnames.end(),
    std::bind2nd(std::ptr_fun(boost::trim<std::string>), std::locale()));

doesn’t work. I get error:

error: ‘typename _Operation::result_type std::binder2nd<_Operation>::operator()(typename _Operation::first_argument_type&) const [with _Operation = std::pointer_to_binary_function<std::basic_string<char>&, const std::locale&, void>; typename _Operation::result_type = void; typename _Operation::first_argument_type = std::basic_string<char>&]’ cannot be overloaded

Why std::bind2nd doesn’t work here?

  • 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:23:17+00:00Added an answer on June 12, 2026 at 12:23 pm

    There are two problems with this I think:

    1. ptr_fun requires that its argument return a value. See:
      http://www.sgi.com/tech/stl/ptr_fun.html

    2. bind2nd doesn’t work with reference arguments. See: Using std::bind2nd with references

    Moral of the story:
    boost::bind hides a shocking amount of complexity.

    If you really want to make it work and don’t care about passing strings/locales by value you can wrap trim as follows:

    int trim2(std::string s, const std::locale loc)
    {
      boost::trim<std::string>(s, loc);
      return 0;
    }
    

    And then do:

    std::for_each(df.colnames.begin(), df.colnames.end(),
        std::bind2nd(std::ptr_fun(trim2), std::locale()));
    

    P.S: (1) may be library-dependent. I just tried with g++ and it didn’t have a problem with a void return.

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

Sidebar

Related Questions

I am trying to use boost::bind with a boost::function using this. It seems a
I'm trying to use Boost.Python as a wrapper for a C++ function that receives
I'm trying to use boost::iterator_facade with an incomplete Value template argument. This fails, because
So, I'm trying to use boost.process library. I downloaded package from this location ,
First part of the question is that I am trying to use boost::bimap, but
I'm trying to use boost.signals library. I know that to use it, first I
I'm scratching my head on this one. I'm trying to use boost::variant to store
I'm trying to use Boost::bind and std::copy to print out the values in a
I'm trying to use boost::bind with the std::sort function. I want to bind sort
I'm trying to use boost::asio for the first time to write a process that

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.