stdbind

c++11 bind and apply?

旧城冷巷雨未停 提交于 2019-12-12 17:25:38
问题 std::bind is sometimes described as "partial application". Any reasons why when all parameters of a function are bound, the function itself isn't applied? For example, the following code prints nothing. #include <functional> #include <iostream> using namespace std; using namespace std::placeholders; void f(int a,string b) {cout << a << b << endl;}; int main() { bind(bind(f,1,_1),"Hi!"); return 0; } Is there a way to write a bind variant that can apply the function when all parameters are

“No matching function for call to… unresolved overloaded function type”

拜拜、爱过 提交于 2019-12-11 16:02:01
问题 I am trying to create a library where the user can modify the behaviour of a function on an instance-level and still manage to access the members of this instance. This post is the continuation of this thread which is the continuation of this one. Praetorian suggested me to use std::function/bind to do that. Unfortunately, I have two errors: Pb #1: error: no matching function for call to ‘Child1::BindIt()’ Pb #2: error: no match for ‘operator=’ (operand types are ‘std::function’ and ‘std::

Difference between std::bind and boost::bind with polymorphism

一曲冷凌霜 提交于 2019-12-10 17:28:18
问题 I have a derived class from which I bind a virtual function that I did not override in this class, so I'm hoping to call the one of the parent class. It works nice with boost (1.55), but if I switch to std::bind from C++11, it refuse to compile with error C2100: illegal indirection 1> functional(1152) : see reference to function template instantiation '_Rx std::_Pmf_wrap<_Pmf_t,_Rx,_Farg0,_V0_t,_V1_t,_V2_t,_V3_t,_V4_t,_V5_t,>::operator ()(_Wrapper &) const' being compiled 1> with 1> [ 1> _Rx

How do I `std::bind` a non-static class member to a Win32 callback function `WNDPROC`?

十年热恋 提交于 2019-12-08 17:51:41
问题 I'm trying to bind a non-static class member to a standard WNDPROC function. I know I can simply do this by making the class member static. But, as a C++11 STL learner, I'm very interested in doing it by using the tools under the <functional> header. My code is as follows. class MainWindow { public: void Create() { WNDCLASSEXW WindowClass; WindowClass.cbSize = sizeof(WNDCLASSEX); WindowClass.style = m_ClassStyles; WindowClass.lpfnWndProc = std::function<LRESULT(HWND, UINT, WPARAM, LPARAM)> (

How to avoid explicit cast with std::bind() temporary objects?

有些话、适合烂在心里 提交于 2019-12-08 04:25:58
问题 The return type of std::bind is (intentionally) unspecified. It is storable in a std::function. The example program below shows how I have to explicitly cast the temporary object returned by std::bind() to a std::function in order to call fn1(). If the return type of std::bind was knowable, I could overload the Callback constructor & would no longer need to explicitly cast std::bind temporary objects. Is there any way to avoid the explicit cast? // g++ -std=c++11 test.cxx #include <functional

How to avoid explicit cast with std::bind() temporary objects?

孤街醉人 提交于 2019-12-08 03:50:28
The return type of std::bind is (intentionally) unspecified. It is storable in a std::function. The example program below shows how I have to explicitly cast the temporary object returned by std::bind() to a std::function in order to call fn1(). If the return type of std::bind was knowable, I could overload the Callback constructor & would no longer need to explicitly cast std::bind temporary objects. Is there any way to avoid the explicit cast? // g++ -std=c++11 test.cxx #include <functional> using std::placeholders::_1; class A { public: void funcA (int x) { } }; class Callback { public:

Store a function with arbitrary arguments and placeholders in a class and call it later

强颜欢笑 提交于 2019-12-08 00:08:31
问题 So I am creating a type of event handler and I am in the process of writing an "Event Listener Wrapper", if you will. The basic idea is this: When you want to subscribe to an event, you create a function that should be called when the event fires. <-- already have that done (kinda, I'll explain) You put this listener function into a wrapper to pass the function onto the dispatcher. The dispatcher gets an event, finds the wrapper for you listener, and calls the underlying function with the

Should I be seeing significant differences between std::bind and boost::bind?

不羁岁月 提交于 2019-12-07 03:56:54
问题 I'm exploring the support for C++11 on the g++-4.7 (Ubuntu/Linaro 4.7.3-2ubuntu~12.04, to be specific) and I seem to be finding differences. In particular, if I comment out #include <boost/bind.hpp> and systematically replace occurrences of boost::bind with std::bind in the Boost ASIO async client example (taken from http://www.boost.org/doc/libs/1_45_0/doc/html/boost_asio/example/http/client/async_client.cpp), the program no longer compiles. Any explanation for this? 回答1: #include

std::bind, this and QtConcurrent

做~自己de王妃 提交于 2019-12-05 19:28:54
Im trying to use std::bind to bind this to method that is used in QtConcurrent::blockingMapped Header: class TuringMachine { private: TRTable table; std::set<ConfigNode*> currentConfigs; //function object std::function<std::set<ConfigNode*>( const TuringMachine*, ConfigNode*)> step_f; //method it will hold std::set<ConfigNode *> step(TuringMachine* this_m ,ConfigNode *parent); std::set<ConfigNode*>& makeStep(); } Source: TuringMachine::TuringMachine(/**/) { step_f = std::bind(&TuringMachine::step, this, std::placeholders::_1); } std::set<ConfigNode*> &TuringMachine::makeStep(){ auto configSet

std::bind and overloaded function

…衆ロ難τιáo~ 提交于 2019-12-05 17:54:48
问题 Please refer the following code snippet. I want to use the std::bind for overloaded function foobar . It calls only the method with no arguments. #include <functional> #include <iostream> class Client { public : void foobar(){std::cout << "no argument" << std::endl;} void foobar(int){std::cout << "int argument" << std::endl;} void foobar(double){std::cout << "double argument" << std::endl;} }; int main() { Client cl; //! This works auto a1 = std::bind(static_cast<void(Client::*)(void)>(