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

  • Home
  • SEARCH
  • 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 6386721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:03:41+00:00 2026-05-25T03:03:41+00:00

I have a Visual Studio 2008 C++ application where I would like to replace

  • 0

I have a Visual Studio 2008 C++ application where I would like to replace a unary functor with a boost::phoenix lambda expression.

In my case, I have list of objects with containing a string. I want to remove all objects with a string that does not match the specified one. So, I use an algorithm like this:

struct Foo
{
    std::string my_type;
};

struct NotMatchType
{
    NotMatchType( const std::string& t ) : t_( t ) { };
    bool operator()( const Foo& f ) const
    {
        return f.my_type.compare( t_ ) != 0;
    };
    std::string t_;
};

int _tmain(int argc, _TCHAR* argv[])
{
    std::vector< Foo > list_of_foo;

    /*populate with objects*/

    std::string some_type = "some type";

    list_of_foo.erase(
        std::remove_if( list_of_foo.begin(),
                        list_of_foo.end(),
                        NotMatchType( some_type ) ),
        list_of_foo.end() );

    return 0;
}

This works fine. But, I’d like to clean up my code a bit and get rid of the NotMatchType functor and replace it with a simple lambda expression like this:

using boost::phoenix::arg_names::arg1;

list_of_foo.erase(
    std::remove_if( list_of_foo.begin(),
                    list_of_foo.end(),
                    arg1.my_type.compare( some_type ) != 0 ),
    list_of_foo.end() );

obviously, this doesn’t work.

I have also tried: ( arg1->*&Foo::my_type ).compare( some_type ) != 0

What do I need to do to make the boost:phoenix:actor look like a Foo object?

  • 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-05-25T03:03:41+00:00Added an answer on May 25, 2026 at 3:03 am

    Given two strings lhs and rhs, then lhs == rhs is specified to be semantically equivalent to lhs.compare(rhs) == 0. In other words, what your functor is doing is equivalent to doing f.my_type != t_.

    With that in mind, you can express what you want with Phoenix as:

    bind(&Foo::my_type, arg1) =! ref(some_type)
    

    For the record, you were calling a member compare on a Phoenix actor. Since that member belongs to std::string though, that’s not what you want. I can get the following to work:

    typedef int (std::string::*compare_type)(std::string const&) const;
    compare_type compare = &std::string::compare;
    bind(compare, bind(&Foo::my_type, arg1), "") != 0;
    

    where that last line is the final functor. But that’s not good because there is no reliable way to get the address of an overloaded member of a Standard type. In other words the second line in the above is not guaranteed to compile.

    For future reference I prefer lambdas when calling an overloaded member:

    auto compare = [](std::string const& lhs, std::string const& rhs)
    { return lhs.compare(rhs); };
    // bind that functor and use it as a Phoenix actor etc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Visual Studio 2008 C++ application where I would like to copy
I have a Visual Studio 2008 C++ application where I would like to convert
I have a Visual Studio 2008 C++ application where I would like to insert
I have a Visual Studio 2008 C++ application that does something like this: template<
I have application written in Visual Studio 2008 which I deploy with ClickOnce to
I have a Web Application project in Visual Studio 2008. (lucky you, you say?
I have a Windows Forms application in C#/Visual Studio 2008 with an IE WebBrowser
I have a GUI C++ application (Visual Studio 2008) that needs to be converted
I'm using Visual Studio 2008 and have created a setup project for my application.
Using Visual Studio 2008, c#, .net 2.0. I have a Windows Forms client application

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.