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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:06:38+00:00 2026-05-16T10:06:38+00:00

I want to suspend a void() function that sets a stack variable to true.

  • 0

I want to suspend a void() function that sets a stack variable to true. How can I do this?

bool flag = false;
boost::function<void()> f = ...;
f();
assert(flag);

This is, obviously, toy code that demonstrates the problem. My attempt at this, using bind, was bind<void>(_1 = constant(true), flag);, but this yields a compilation error.

  • 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-16T10:06:38+00:00Added an answer on May 16, 2026 at 10:06 am

    To use boost::bind, you’d need to make a function that sets a boolean to true, so you can bind to it:

    #include <boost/bind.hpp>
    #include <boost/function.hpp>
    #include <boost/ref.hpp>
    
    void make_true(bool& b)
    {
        b = true;
    }
    
    int main()
    {
        using namespace boost;
    
        bool flag = false;
    
        // without ref, calls with value of flag at the time of binding
        // (and therefore would call make_true with a copy of flag, not flag)
        function<void()> f = bind(make_true, ref(flag)); 
    
        f();
        assert(flag);
    }
    

    However, lambda’s will help here. Lambda’s are like bind, except they make functions too, so keep your code localized (no need for some external function). You’d do something like this:

    #include <boost/function.hpp>
    #include <boost/lambda/lambda.hpp>
    
    int main()
    {
        using namespace boost;
        using namespace boost::lambda;
    
        bool flag = false;
    
        function<void()> f = (var(flag) = true);
    
        f();
        assert(flag);
    }
    

    Same idea, except bind and make_true has been replaced with a lambda.

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

Sidebar

Related Questions

i am using this code for suspend process.i found it here http://www.codeproject.com/KB/threads/pausep.aspx BOOL SuspendResumeThreadList(DWORD
Want to run javascript function from parent window in child window Example I have
want to have a Hyperlink-Button in a gridView in which I can display a
Want the function to sort the table by HP but if duplicate HPs then
I can suspend the thread with user input in console,but can't resume it again
I want to suspend users in my Rails application. I am using Devise. I
The question is how can I test the fact that object disposes resources when
I want to suspend (pause) a forked process at startup and resume it later
I can suspend a thread of another process by using SuspendThread(). Is there any
In Win32 I want to suspend a thread using Suspend(GetCurrentThread()); but I find I

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.