Questions tagged [boost-bind]

boost::bind is a generalization of the standard C++ functions std::bind1st and std::bind2nd. It supports arbitrary function objects, functions, function pointers, and member function pointers, and is able to bind any argument to a specific value or route input arguments into arbitrary positions.

boost::bind is a generalization of the standard C++ functions std::bind1st and std::bind2nd. It supports arbitrary function objects, functions, function pointers, and member function pointers, and is able to bind any argument to a specific value or route input arguments into arbitrary positions. bind does not place any requirements on the function object; in particular, it does not need the result_type, first_argument_type and second_argument_type standard typedefs.

boost::bind was proposed for standardization and a version of it was included in as std::tr1::bind and an improved version is included in the standard as std::bind (see ).

352 questions
1
vote
0 answers

boost::bind placeholder issue when binding Handler to a boost::asio::strand

void Connection::HandleRecvData(const boost::system::error_code & error) { boost::asio::async_read( m_socket, boost::asio::buffer( m_recv_buffer ), m_io_strand.wrap( boost::bind( &Connection::HandleRecvData, …
jpalm
  • 11
  • 3
1
vote
1 answer

boost::bind & boost::function with partial args

I post you an example of what I want to do, that is easier to explain in this way void myPrinter(const char* text, int number){ printf("\n%s %d\n", text, number); } int main() { char…
M4rk
  • 2,172
  • 5
  • 36
  • 70
1
vote
2 answers

Handler requirement for Asynchronous Operation in boost::asio

It is specified in boost::asio document that a handler for async_accept() must satisfy the following function signature: void accept_handler( const boost::system::error_code& ec) { ... } However, in the Daytime.3 example, using boost::bind,…
Amumu
  • 17,924
  • 31
  • 84
  • 131
1
vote
1 answer

function with templates and boost

I try to write a functor to call a boost function with bind and some template. So i have this main : int function(char c) { std::cout << c << std::endl; return (0); } int main() { Function fb = boost::bind(&function, _1); …
Adrien A.
  • 441
  • 2
  • 12
  • 31
1
vote
0 answers

boost::function alike class

I would like to realize a class Function similar to boost::function, the class Function can use like this in main.cpp : #include #include "Function.hpp" int funct1(char c) { std::cout << c << std::endl; return 0; } int main() { …
1
vote
3 answers

Problem with boost::bind and member function returning auto_ptr

Why does this code fail to compile with VS 2005: #include #include struct X { typedef std::auto_ptr IntType; // typedef int IntType; // this works IntType memfunc () const { return…
jon hanson
  • 8,722
  • 2
  • 37
  • 61
1
vote
2 answers

Bind function pointer to boost::function object

How can I initialize a boost::function object with a raw function pointer? Metacode extern "C" { class Library { ... }; Library* createLibrary(); } ... void* functionPtr =…
Mythli
  • 5,995
  • 2
  • 24
  • 31
1
vote
2 answers

boost bind callback function pointer as a parameter

I am trying to pass a function pointer using boost::bind. void Class::ThreadFunction(Type(*callbackFunc)(message_type::ptr&)) { } boost::shared_ptr Class::Init(Type(*callbackFunc)(message_type::ptr&)) { return…
Ivan Santos
  • 624
  • 1
  • 8
  • 21
1
vote
2 answers

Boost::Bind noncopyable error with shared_ptr

I am trying the following: boost::shared_ptr< tcp::socket > socket(new tcp::socket( *io_service)); boost::bind(&function, *socket); // compiler error: noncopyable error function(*socket); // this works fine void function(tcp::socket & socket) { …
Ivan Santos
  • 624
  • 1
  • 8
  • 21
1
vote
2 answers

Calling a function with different number of threads passed to the application

I have a function which needs to be invoked with a different number of threads each time (am doing some performance calculation, so need to know when the performance starts deteriorating). Example is given below: getTime() { return 0; } int…
gagneet
  • 35,729
  • 29
  • 78
  • 113
1
vote
1 answer

Implement no-op functor using boost::bind

I have a function void get(boost::function callback) { callback(); }. I want to make a call like get(boost::bind(/* don't know what to put here*/)); without implementing any other functions, variables or structs, so that the callback…
abyss.7
  • 13,882
  • 11
  • 56
  • 100
1
vote
1 answer

boost::bind, boost::shared_ptr and inheritance

I'm new with the Boost library, and I got a problam a bit complex for me. I tried to reformulate it with an example found in previous question that might fit well my problem. (The previous question is here) #include #include…
etnbrd
  • 471
  • 6
  • 18
1
vote
1 answer

Boost bind inside Boost packaged_task. Why boost asio thinks its not CompletionHandler?

So all my work happens inside of a class named thread_pool. This code will work no matter what run_item takes into itself: template void thread_pool::pool_item( boost::shared_ptr< boost::packaged_task > pt) …
Rella
  • 65,003
  • 109
  • 363
  • 636
1
vote
1 answer

C++ and boost 1.71 - error: reference to ‘_1’ is ambiguous

I am using the libraries websocketcpp and boost 1.71. The code used to work with boost 1.58 but after upgrading both libraries, it won't compile. The C++ compiler is g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 and the code is the following: using…
grouser
  • 618
  • 8
  • 23
1
vote
2 answers

Comparing objects returned by Boost.Bind?

Is it possible? The instruction bool b = (boost::bind(func, 1) == boost::bind(func, 1)) does not compile because it "cannot convert from 'boost::_bi::bind_t' to 'bool'". (The signature of func is void func(int).)
Paul Manta
  • 30,618
  • 31
  • 128
  • 208