boost-bind

Boost::asio and boost::bind: Functor memory is never released

最后都变了- 提交于 2019-12-24 05:14:08
问题 My code is allocating memory and never freeing it, even though it should (at least in my opinion). The header looks like this: typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> sslSocket_t; class Object { boost::asio::io_service ioService_; boost::asio::ip::tcp::acceptor acceptor_; boost::asio::ssl::context context_; void functionOne(); void functionTwo(shared_ptr<sslSocket_t>& sslSocket, const boost::system::error_code& error) } And my source like this: void Object::functionOne(

boost::bind together with boost::asio. boost::bind not working, copied from an example

放肆的年华 提交于 2019-12-24 03:12:36
问题 Could someone tell me why this does not compile? I basically copied it from an example by Kholkoff (http://lists.boost.org/Archives/boost/2007/04/120339.php), back in 2007, about reads() in sockets with timeouts: void CClient::setResult(boost::optional<boost::system::error_code>* a,boost::system::error_code b) { *a = b; } I'm binding() it like this: timer.async_wait(boost::bind(&CClient::setResult, &timer_result, _1)); The errors that gcc prints are unreadable to me: static assertion failed:

Storing function pointers with different types c++ boost::bind

ⅰ亾dé卋堺 提交于 2019-12-24 02:42:37
问题 I have dug around quite a bit today and have come up empty. Is there any way to store a functor that is returned from a boost::bind with different types? I found an example that used boost::variants but not sure that this is needed. (Foo and Bar have been simplified for simplicity sake) #include <boost/bind.hpp> #include <boost/variant.hpp> #include <boost/function.hpp> #include <map> #include <iostream> template <typename FooType> struct Foo { const FooType tmp_value; Foo(const FooType& tmp_

Using boost::asio::io_service::post()

冷暖自知 提交于 2019-12-23 12:14:31
问题 First i asked this Running a function on the main thread from a boost thread and passing parameters to that function so now i am trying this: The following is a console c++ project where i perfectly simulated my big project TestServicePost.cpp #include "stdafx.h" #include "SomeClass.h" int _tmain(int argc, _TCHAR* argv[]) { SomeClass* s = new SomeClass(); while(true) { s->update(); } return 0; } SomeClass.h #include <boost/thread.hpp> #include <boost/asio.hpp> #include <queue> class

sort using boost::bind

落花浮王杯 提交于 2019-12-23 03:25:28
问题 bool pred(int k, int l, int num1, int num2) { return (num1 < num2); } int main() { vector <int> nums; for (int i=50; i > 0; --i) { nums.push_back(i); } std::sort (nums.begin(), nums.end(), boost::bind(&pred, 5, 45)); } I am a boost newbie. I was learning to use boost::bind and I wanted to sort a vector of integers and get rid of all those elements in the vector that are greater than 45 and less than 5. Had a hard time doing it. Would be great if anyone could help me do it? The reason I am

Using boost::bind and boost::lambda::new_ptr to return a shared_ptr constructor

十年热恋 提交于 2019-12-22 10:38:23
问题 Given a class A, class A { public: A(B&) {} }; I need a boost::function<boost::shared_ptr<A>(B&)> object. I prefer not to create an ad-hoc function boost::shared_ptr<A> foo(B& b) { return boost::shared_ptr<A>(new A(b)); } to solve my problem, and I'm trying to solve it binding lambda::new_ptr. boost::function<boost::shared_ptr<A> (B&)> myFun = boost::bind( boost::type<boost::shared_ptr<A> >(), boost::lambda::constructor<boost::shared_ptr<A> >(), boost::bind( boost::type<A*>(), boost::lambda:

What's the use of asio::placeholder::error

时光怂恿深爱的人放手 提交于 2019-12-22 03:48:48
问题 The asio library passes an error parameter in a lot of its examples, ie; http://think-async.com/Asio/asio-1.5.3/src/examples/echo/async_tcp_echo_server.cpp What's the point of this parameter? Does asio actually populate this parameter with errors? If I remove it from my handler function it compiles fine. 回答1: Actually, asio::placeholders::error is equivalent to _1 Boost.Bind placeholder, so bind(&my_class::handler, this, asio::placeholders::error) is just like bind(&my_class::handler, this,

C++ generic factory with multiple constructor signatures?

折月煮酒 提交于 2019-12-21 19:24:57
问题 Has anyone ever combined the classic generic factory by Andrei Alexandrescu (page 208 of Chapter 8 in Modern C++ Design) with the 'multifunction' capabilities of Boost.TypeErasure? That is, the flexibility to have several creator function signatures that vary with respect to number and type of parameters (but still have the same return type and are known at compile time). In other words, how to combine this slightly simplified generic Factory: #include <map> #include <utility> #include

How to use boost::bind with non-copyable params, for example boost::promise?

Deadly 提交于 2019-12-21 07:57:23
问题 Some C++ objects have no copy constructor, but have move constructor. For example, boost::promise. How can I bind those objects using their move constructors ? #include <boost/thread.hpp> void fullfil_1(boost::promise<int>& prom, int x) { prom.set_value(x); } boost::function<void()> get_functor() { // boost::promise is not copyable, but movable boost::promise<int> pi; // compilation error boost::function<void()> f_set_one = boost::bind(&fullfil_1, pi, 1); // compilation error as well boost:

How to use boost::bind with non-copyable params, for example boost::promise?

本小妞迷上赌 提交于 2019-12-21 07:57:07
问题 Some C++ objects have no copy constructor, but have move constructor. For example, boost::promise. How can I bind those objects using their move constructors ? #include <boost/thread.hpp> void fullfil_1(boost::promise<int>& prom, int x) { prom.set_value(x); } boost::function<void()> get_functor() { // boost::promise is not copyable, but movable boost::promise<int> pi; // compilation error boost::function<void()> f_set_one = boost::bind(&fullfil_1, pi, 1); // compilation error as well boost: