boost/bind.hpp

纯C++风格,没有使用#include <boost/bind.hpp>

 

复制代码

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <functional>
 4 #include <vector>
 5 
 6 class add :public std::binary_function<int, int, void>
 7 {
 8 public:
 9     void operator()(int i, int j)const
10     {
11         std::cout << i + j << std::endl;
12     }
13 };
14 
15 void main()
16 {
17     std::vector<int>myv;
18 
19     myv.push_back(11);
20     myv.push_back(23);
21     myv.push_back(34);
22 
23     for_each(myv.begin(), myv.end(), std::bind1st(add(), 10));//实现每个元素+10并输出,但不改变原有的元素
24 }

复制代码

 

使用#include <boost/bind.hpp>

 

复制代码

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <functional>
 4 #include <vector>
 5 #include <boost/bind.hpp>
 6 
 7 void add(int i, int j)
 8 {
 9     std::cout << i + j << std::endl;
10 }
11 
12 void main()
13 {
14     std::vector<int>myv;
15 
16     myv.push_back(11);
17     myv.push_back(23);
18     myv.push_back(34);
19 
20     for_each(myv.begin(), myv.end(), boost::bind(add, 13, _1));//实现每个元素+13并输出,但不改变原有的元素
21 }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
帮我修改下面的代码。要求建立一次weboscket链接,链接到wss://autopilot-test.t3go.cn:443/api/v1/vehicle/push/message/LFB1FV696M2L43840,当订阅到感知话题调用perceptionCallback时,通过wss发送serialized_data:#include "ros/ros.h" #include "std_msgs/String.h" #include <boost/thread/locks.hpp> #include <boost/thread/shared_mutex.hpp> #include "third_party/apollo/proto/perception/perception_obstacle.pb.h" #include "t3_perception.pb.h" #include <iostream> #include <websocketpp/config/asio_client.hpp> #include <websocketpp/client.hpp> #include <websocketpp/common/thread.hpp> apollo::perception::PerceptionObstacles perception_obstacles_; typedef websocketpp::clientwebsocketpp::config::asio_tls_client client; void perceptionCallback(const std_msgs::String& msg) { ROS_WARN("t3 perceptionCallback parse"); if (perception_obstacles_.ParseFromString(msg.data)) { double timestamp = perception_obstacles_.header().timestamp_sec(); ROS_INFO("t3 perceptionCallback timestamp %f count:%d", timestamp, perception_obstacles_.perception_obstacle().size()); std::string data; perception_obstacles_.SerializeToString(&data); VehData veh_data; veh_data.set_messagetype(5); veh_data.set_messagedes("PerceptionObstacles"); veh_data.set_contents(data); std::string serialized_data; veh_data.SerializeToString(&serialized_data); } else { ROS_ERROR("t3 perceptionCallback parse fail!"); } } int main(int argc, char **argv) { ros::init(argc, argv, "listener"); ros::NodeHandle n; ros::Subscriber sub = n.subscribe("/perception_node/perception_objects", 1000, perceptionCallback); ros::spin(); return 0; }
06-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值