Category : stdbind

Trying to get the function object from std::bind() using following code: std::function<void(mqtt::const_message_ptr, mqtt::async_client*,callback*,sql::Driver*)> fn = std::bind(&driver_manager::test_callback, &driverManager, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4); Results in error: error: conversion from ‘std::_Bind_helper<false, void (driver_manager::*)(std::shared_ptr<const mqtt::message>, mqtt::async_client*, callback*, sql::Driver*), driver_manager (*)(), const std::_Placeholder<1>&, const std::_Placeholder<2>&, const std::_Placeholder<3>&, const std::_Placeholder<4>&>::type’ to non-scalar type ‘std::function<void(std::shared_ptr<const mqtt::message>, mqtt::async_client*, callback*, sql::Driver*)>’ requested I have ..

Read more

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 *)> callback_func, const std::string & window_name = "Open3D", int width = 640, int height = 480, int left = 50, int top = 50 ) I have managed to get it working, if ..

Read more

In the following minimal example: #include <iostream> #include <functional> class Non_movable{ public: Non_movable(void){ } Non_movable(const Non_movable& other) = delete;/* Copy constructor */ Non_movable(Non_movable&& other) = delete; /* Move constructor */ Non_movable& operator=(const Non_movable& other) = delete; /* Copy assignment */ Non_movable& operator=(Non_movable&& other) = delete; /* Move assignment */ }; template<typename …T> std::function<void(int)> make_bound(T… args, ..

Read more

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, boost::asio::ip::tcp::socket socket); I have noticed that this piece of code compiles: auto strand = net::make_strand(io_context_); std::shared_ptr<server> this_pointer = shared_from_this(); acceptor_.async_accept( strand, boost::beast::bind_front_handler(&server::on_accept, this_pointer) ); whereas this does not: auto strand = net::make_strand(io_context_); std::shared_ptr<server> ..

Read more

auto dis_calculator = std::bind(&LaneTrackerImpl::calc_lane_distance, this, std::placeholders::_1, std::placeholders::_2, false, 0.0f, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6); I write code like this auto lane_distance_calculator = [this](const Lane &lane1, const Lane &lane2, bool disable_lane_start_distance_affection, bool disable_lane_end_distance_affection, DistanceMethod method, bool is_matching_phase){ LaneTrackerImpl::calc_lane_distance(lane1,lane2,false, 0.0f, disable_lane_start_distance_affection, disable_lane_end_distance_affection, method, is_matching_phase ); error: expected ‘,’ or ‘;’ before ‘merge_lanes’ but the error happened How can ..

Read more

I have the following scenario quite often in my c++17 code. Generic example: class Receiver{ public: typedef std::function<void(const std::vector<uint8_t>& payload)> PROCESS_PACKET; PROCESS_PACKET m_callback; void run(){ while(){ // do stuff, then call callback: m_callback(data); } } }; class UsesReceiver{ public: UsesReceiver(){ receiver.m_callback=std::bind(&UsesReceiver::processData, this, std::placeholders::_1); receiver.run(); } private: void processData(const std::vector<uint8_t>& payload){ // here do something implementation ..

Read more