Questions tagged [stdbind]

The C++11 function std::bind() fixes some or all arguments of a function object, returning another function object that takes fewer arguments.

std::bind performs Partial Function Application of arbitrary C++ function objects, fixing some or all arguments of a function object and returning another function object that takes fewer arguments.

The function is based on boost::bind() which originated in the library (see ) and an earlier version was included in as std::tr1::bind().

371 questions
1
vote
1 answer

lambda iso std::bind for member function

I have the following class on which I run clang-tidy. template class Bar { public: template Bar(void (THandlerObj::*pCmdHandler)(const Foo&), THandlerObj* pCmdHandlerContext) …
Frank
  • 2,446
  • 7
  • 33
  • 67
1
vote
1 answer

Binding a std::function to a member function in c++?

I'm working with Open3D library using the following function: bool open3d::visualization::DrawGeometriesWithAnimationCallback ( const std::vector< std::shared_ptr< const geometry::Geometry >> & geometry_ptrs, std::function< bool(Visualizer *)>…
Roland Deschain
  • 2,211
  • 19
  • 50
1
vote
1 answer

How to bind reference of non-movable object in variadic template arguments?

In the following minimal example: #include #include class Non_movable{ public: Non_movable(void){ } Non_movable(const Non_movable& other) = delete;/* Copy constructor */ Non_movable(Non_movable&& other) = delete; /*…
Dávid Tóth
  • 2,788
  • 1
  • 21
  • 46
1
vote
1 answer

Cannot store bind_front_handler return value in variable

With these present in other parts of my codebase, namespace net = boost::asio; using boost::asio::ip::tcp; boost::asio::io_context& io_context_; tcp::acceptor acceptor_; void server::on_accept(boost::beast::error_code ec,…
1
vote
1 answer

Reassign std::function with std::bind during execution

I'm trying to implement a logic in my code for which I have several backup mechanism if a certain approach fails. class Foo { public: Foo() { func = std::bind(&Foo::f1, this); } void f1() { func = std::bind(&Foo::f2, this); …
Mdp11
  • 552
  • 4
  • 13
1
vote
3 answers

Is there an alternative to std::bind that doesn't require placeholders if function declarations match?

I have the following scenario quite often in my c++17 code. Generic example: class Receiver{ public: typedef std::function& payload)> PROCESS_PACKET; PROCESS_PACKET m_callback; void run(){ …
Constantin Geier
  • 303
  • 4
  • 13
1
vote
1 answer

Write templated recursive integration method that accepts generic n-dimensional functions

I am working on a large C++ framework to do some particle physics computation and it would be nice to have a method to do N-dimensional integration of a generic function with N variables. The integration happens on the N-cube [0:1]^N. The integrand…
tboschi
  • 124
  • 11
1
vote
2 answers

Use std::bind and store into a std:: function

I am trying to use std::bind to bind to a function and store it into my std::function callback object. The code I wrote is the simplified version of my actual code. The below code does not compile, says _1 was not declared in the scope Note: I…
Soumyajit Roy
  • 463
  • 2
  • 8
  • 17
1
vote
1 answer

Is it possible to access the arguments from an std::bind object?

Please consider the following scenario. A hypothetical pop-up menu class that displays some actions, and when one of them is selected it will call the passed in action which is in form of an…
santahopar
  • 2,933
  • 2
  • 29
  • 50
1
vote
1 answer

C++ I don't know what it means to use "this" and "std::placeholders::_1" when using the callback function

I am trying to make a server by looking at the sample code of cpprestSDK. But I don't know why I bind in the sample code. Below is the sample code. stdafx.h class Handler{ public: Handler() {}; Handler(utility::string_t url); …
Hwan E
  • 566
  • 2
  • 13
1
vote
3 answers

Is it possible to forward function calls with matching template type for a std::any-like container?

I haven't found a way to achieve what I want but I'm not knowledgeable enough to know if its impossible. Help would be appreciated. The main data data container in our software behaves a bit like a std::variant or std::any: It has a base class…
emmenlau
  • 958
  • 12
  • 20
1
vote
0 answers

How to write std::function for variable arguments?

I want to pass std::function as a callback parameter to another function. The function to be bound is a static function with variable argument list. The static function is as follows: void abc::static_func(const char* const text,...); abc is a…
1
vote
1 answer

Is the 'this' pointer able to be used inside of a c++ header declaration?

Using repl, it appears to be completely legal, however is there any undefined behavior/compiler-specific issues at play here? https://repl.it/repls/ContentPutridMacro googling for the 'this' usage inside of a header doesn't seem to turn up anything…
1
vote
0 answers

Passing a member function as parameter to multiple levels of classes

I have 3 different classes, the class - consumer is being used by the user. I basically wanted the user to give the method that has to be executed in case of error in worker. So I have to pass this to worker class somehow The consumer class…
1
vote
0 answers

How to handle placeholders in variadic templates for a threadpool

I'm implementing a threadPool with waitable tasks. The threadPool saves tasks in a threadsafe deque, here threadsafeQueue. Tasks are callable objects where almost all of the arguments are bound with std::bind except of the last. I…
d.m.q.
  • 31
  • 4