Skip to content

Replaced instances of boost::bind with std::bind or lambda functions. #3410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions docs/coroutine_test_examples.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <boost/bind.hpp>
#include <boost/coroutine2/all.hpp>
#include <functional>
#include <iostream>
Expand All @@ -12,7 +11,7 @@ class FunctionMemberObject
explicit FunctionMemberObject(TestFunction func, std::shared_ptr<int> data)
: func(func),
coroutine_sequence(
boost::bind(&FunctionMemberObject::executeWrapper, this, _1, data))
std::bind(&FunctionMemberObject::executeWrapper, this, std::placeholders::_1, data))
{
}

Expand Down Expand Up @@ -46,7 +45,7 @@ class DataMemberObject
explicit DataMemberObject(TestFunction func, std::shared_ptr<int> data)
: data(data),
coroutine_sequence(
boost::bind(&DataMemberObject::executeWrapper, this, _1, func))
std::bind(&DataMemberObject::executeWrapper, this, std::placeholders::_1, func))
{
}

Expand Down Expand Up @@ -78,7 +77,7 @@ class NoMemberObject
{
public:
explicit NoMemberObject(TestFunction validation_function, std::shared_ptr<int> data)
: coroutine_sequence(boost::bind(&NoMemberObject::executeWrapper, this, _1, data,
: coroutine_sequence(std::bind(&NoMemberObject::executeWrapper, this, std::placeholders::_1, data,
validation_function))
{
}
Expand Down
1 change: 0 additions & 1 deletion src/software/ai/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ cc_library(
"//software/multithreading:subject",
"//software/multithreading:threaded_observer",
"//software/world",
"@boost//:bind",
],
)

Expand Down
7 changes: 4 additions & 3 deletions src/software/ai/hl/stp/play/play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Play::Play(TbotsProto::AiConfig ai_config, bool requires_goalie)
goalie_tactic(std::make_shared<GoalieTactic>(ai_config)),
halt_tactics(),
requires_goalie(requires_goalie),
tactic_sequence(boost::bind(&Play::getNextTacticsWrapper, this, _1)),
tactic_sequence(
std::bind(&Play::getNextTacticsWrapper, this, std::placeholders::_1)),
world_ptr_(std::nullopt),
obstacle_factory(ai_config.robot_navigation_obstacle_config())
{
Expand All @@ -42,7 +43,7 @@ PriorityTacticVector Play::getTactics(const WorldPtr &world_ptr)
{
// Make a new tactic_sequence
tactic_sequence = TacticCoroutine::pull_type(
boost::bind(&Play::getNextTacticsWrapper, this, _1));
std::bind(&Play::getNextTacticsWrapper, this, std::placeholders::_1));
// Run the coroutine. This will call the bound getNextTactics function
tactic_sequence();
}
Expand All @@ -61,7 +62,7 @@ PriorityTacticVector Play::getTactics(const WorldPtr &world_ptr)
{
// Make a new tactic_sequence
tactic_sequence = TacticCoroutine::pull_type(
boost::bind(&Play::getNextTacticsWrapper, this, _1));
std::bind(&Play::getNextTacticsWrapper, this, std::placeholders::_1));
// Run the coroutine. This will call the bound getNextTactics function
tactic_sequence();
if (tactic_sequence)
Expand Down
1 change: 0 additions & 1 deletion src/software/ai/hl/stp/play/play.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <boost/bind.hpp>
#include <boost/coroutine2/all.hpp>
#include <vector>

Expand Down
2 changes: 0 additions & 2 deletions src/software/ai/threaded_ai.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "software/ai/threaded_ai.h"

#include <boost/bind.hpp>

#include "proto/message_translation/tbots_protobuf.h"
#include "proto/parameters.pb.h"
#include "software/ai/hl/stp/play/assigned_tactics_play.h"
Expand Down
9 changes: 7 additions & 2 deletions src/software/embedded/services/network/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ NetworkService::NetworkService(const std::string& ip_address,
udp_listener_primitive_set =
std::make_unique<ThreadedProtoUdpListener<TbotsProto::PrimitiveSet>>(
ip_address, primitive_listener_port,
boost::bind(&NetworkService::primitiveSetCallback, this, _1), multicast);
[&](TbotsProto::PrimitiveSet primitive_set) {
primitiveSetCallback(primitive_set);
},
multicast);

radio_listener_primitive_set =
std::make_unique<ThreadedProtoRadioListener<TbotsProto::PrimitiveSet>>(
boost::bind(&NetworkService::primitiveSetCallback, this, _1));
[&](TbotsProto::PrimitiveSet primitive_set) {
primitiveSetCallback(primitive_set);
});
}

TbotsProto::PrimitiveSet NetworkService::poll(TbotsProto::RobotStatus& robot_status)
Expand Down
3 changes: 1 addition & 2 deletions src/software/embedded/services/power.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "software/embedded/services/power.h"

#include <boost/bind/bind.hpp>
#include <boost/filesystem.hpp>
#include <cstdint>

Expand All @@ -15,7 +14,7 @@ PowerService::PowerService()
throw std::runtime_error("USB not plugged into the Jetson Nano");
}
this->uart = std::make_unique<BoostUartCommunication>(BAUD_RATE, DEVICE_SERIAL_PORT);
this->read_thread = std::thread(boost::bind(&PowerService::continuousRead, this));
this->read_thread = std::thread(std::bind(&PowerService::continuousRead, this));
}

PowerService::~PowerService()
Expand Down
10 changes: 4 additions & 6 deletions src/software/estop/threaded_estop_reader.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

#include "threaded_estop_reader.h"

#include <boost/bind/bind.hpp>
#include <thread>
#include <utility>

Expand All @@ -12,13 +10,13 @@ ThreadedEstopReader::ThreadedEstopReader(std::unique_ptr<UartCommunication> uart
timer(io_service, boost::posix_time::milliseconds(INTERVAL_BETWEEN_READS_MS)),
uart_reader(std::move(uart_reader))
{
estop_thread = std::thread(boost::bind(&ThreadedEstopReader::continousRead, this));
estop_thread = std::thread(std::bind(&ThreadedEstopReader::continousRead, this));
}

void ThreadedEstopReader::continousRead()
{
timer.async_wait(
boost::bind(&ThreadedEstopReader::tick, this, boost::asio::placeholders::error));
std::bind(&ThreadedEstopReader::tick, this, boost::asio::placeholders::error));
io_service.run();
}

Expand Down Expand Up @@ -87,8 +85,8 @@ void ThreadedEstopReader::tick(const boost::system::error_code& error)
// Reschedule the timer for interval seconds in the future:
timer.expires_from_now(next_interval);
// Posts the timer event
timer.async_wait(boost::bind(&ThreadedEstopReader::tick, this,
boost::asio::placeholders::error));
timer.async_wait(std::bind(&ThreadedEstopReader::tick, this,
boost::asio::placeholders::error));
}
}

Expand Down
1 change: 0 additions & 1 deletion src/software/multithreading/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ cc_library(
":observer",
":thread_safe_buffer",
"//software/time:duration",
"@boost//:bind",
],
)

Expand Down
5 changes: 2 additions & 3 deletions src/software/multithreading/threaded_observer.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <boost/bind.hpp>
#include <thread>

#include "software/multithreading/observer.hpp"
Expand Down Expand Up @@ -88,8 +87,8 @@ ThreadedObserver<T>::ThreadedObserver(size_t buffer_size, bool log_buffer_full)
in_destructor(false),
IN_DESTRUCTOR_CHECK_PERIOD(Duration::fromSeconds(0.1))
{
pull_from_buffer_thread = std::thread(
boost::bind(&ThreadedObserver::continuouslyPullValuesFromBuffer, this));
pull_from_buffer_thread =
std::thread(std::bind(&ThreadedObserver::continuouslyPullValuesFromBuffer, this));
}

template <typename T>
Expand Down
7 changes: 3 additions & 4 deletions src/software/networking/udp/proto_udp_listener.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <condition_variable>
#include <mutex>
#include <string>
Expand Down Expand Up @@ -156,9 +155,9 @@ void ProtoUdpListener<ReceiveProtoT>::startListen()
// https://stackoverflow.com/questions/34680985/what-is-the-difference-between-asynchronous-programming-and-multithreading
socket_.async_receive_from(boost::asio::buffer(raw_received_data_, MAX_BUFFER_LENGTH),
sender_endpoint_,
boost::bind(&ProtoUdpListener::handleDataReception, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
std::bind(&ProtoUdpListener::handleDataReception, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
}

template <class ReceiveProtoT>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <string>

#include "software/networking/udp/threaded_udp_sender.h"
Expand Down
1 change: 0 additions & 1 deletion src/software/networking/udp/threaded_udp_sender.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <string>

#include "software/networking/udp/udp_sender.h"
Expand Down
1 change: 0 additions & 1 deletion src/software/networking/udp/udp_sender.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <string>

class UdpSender
Expand Down
7 changes: 3 additions & 4 deletions src/software/networking/unix/proto_unix_listener.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <string>

#include "software/constants.h"
Expand Down Expand Up @@ -90,9 +89,9 @@ void ProtoUnixListener<ReceiveProtoT>::startListen()
// https://stackoverflow.com/questions/34680985/what-is-the-difference-between-asynchronous-programming-and-multithreading
socket_.async_receive_from(boost::asio::buffer(raw_received_data_, UNIX_BUFFER_SIZE),
listen_endpoint_,
boost::bind(&ProtoUnixListener::handleDataReception, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
std::bind(&ProtoUnixListener::handleDataReception, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
}

template <class ReceiveProtoT>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <string>

#include "software/networking/unix/threaded_unix_sender.h"
Expand Down
1 change: 0 additions & 1 deletion src/software/networking/unix/threaded_unix_sender.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "software/networking/unix/threaded_unix_sender.h"

#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <string>

ThreadedUnixSender::ThreadedUnixSender(const std::string& unix_socket_path)
Expand Down
1 change: 0 additions & 1 deletion src/software/networking/unix/threaded_unix_sender.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <string>

#include "software/networking/unix/unix_sender.h"
Expand Down
1 change: 0 additions & 1 deletion src/software/networking/unix/unix_sender.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <string>
#include <type_traits>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

#include <gtest/gtest.h>

#include <boost/bind.hpp>

NonTerminatingFunctionValidator::NonTerminatingFunctionValidator(
ValidationFunction validation_function, std::shared_ptr<World> world)
: // We need to provide the world and validation_function in the coroutine function
// binding so that the wrapper function has access to the correct variable context,
// otherwise the World inside the coroutine will not update properly when the
// pointer is updated, and the wrong validation_function may be run.
validation_sequence(
boost::bind(&NonTerminatingFunctionValidator::executeAndCheckForFailuresWrapper,
this, _1, world, validation_function)),
std::bind(&NonTerminatingFunctionValidator::executeAndCheckForFailuresWrapper,
this, std::placeholders::_1, world, validation_function)),
world_(world),
validation_function_(validation_function)
{
Expand All @@ -24,9 +22,9 @@ std::optional<std::string> NonTerminatingFunctionValidator::executeAndCheckForFa
if (!validation_sequence)
{
// Re-start the coroutine by re-creating it
validation_sequence = ValidationCoroutine::pull_type(boost::bind(
&NonTerminatingFunctionValidator::executeAndCheckForFailuresWrapper, this, _1,
world_, validation_function_));
validation_sequence = ValidationCoroutine::pull_type(
std::bind(&NonTerminatingFunctionValidator::executeAndCheckForFailuresWrapper,
this, std::placeholders::_1, world_, validation_function_));
}

// Run the coroutine. This will call the bound executeAndCheckForFailuresWrapper
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "software/simulated_tests/validation/terminating_function_validator.h"

#include <boost/bind.hpp>

TerminatingFunctionValidator::TerminatingFunctionValidator(
ValidationFunction validation_function,
std::shared_ptr<World> world)
Expand All @@ -10,8 +8,8 @@ TerminatingFunctionValidator::TerminatingFunctionValidator(
// otherwise the World inside the coroutine will not update properly when the
// pointer is updated, and the wrong validation_function may be run.
validation_sequence(
boost::bind(&TerminatingFunctionValidator::executeAndCheckForSuccessWrapper,
this, _1, world, validation_function)),
std::bind(&TerminatingFunctionValidator::executeAndCheckForSuccessWrapper, this,
std::placeholders::_1, world, validation_function)),
current_error_message("")
{
}
Expand Down