Skip to content

Commit

Permalink
Embrace std::invoke (C++17)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterBowman committed Aug 22, 2023
1 parent f9505fa commit 3778720
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion libraries/YarpDeviceMapperLib/DeviceMapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#ifndef __DEVICE_MAPPER_HPP__
#define __DEVICE_MAPPER_HPP__

#include <functional> // std::invoke
#include <memory>
#include <string>
#include <tuple>
Expand Down Expand Up @@ -173,7 +174,7 @@ class DeviceMapper final
{
auto [device, offset] = getDevice(j);
T * p = device->getHandle<T>();
return p ? (p->*fn)(offset, ref...) : false;
return p ? std::invoke(fn, p, offset, ref...) : false;
}

//! Alias for a full-joint command. See class description.
Expand Down
2 changes: 1 addition & 1 deletion libraries/YarpDeviceMapperLib/FutureTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FutureTask
//! Register a deferred callback given a generic class instance.
template<typename T, typename Fn, typename... Args>
void add(T * p, Fn && fn, Args &&... args)
{ deferreds.push_back([=](int) { return (p->*fn)(args...); }); }
{ deferreds.push_back([=](int) { return std::invoke(fn, p, args...); }); }

//! Dispatch the registered callbacks and returns their joint result.
virtual bool dispatch() = 0;
Expand Down
4 changes: 3 additions & 1 deletion libraries/YarpPlugins/CanBusControlboard/IPidControlImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "CanBusControlboard.hpp"

#include <functional> // std::invoke

#include <yarp/os/Log.h>
#include <yarp/os/Vocab.h>

Expand All @@ -21,7 +23,7 @@ namespace
{
auto [device, offset] = dm.getDevice(j);
auto * p = device->getHandle<yarp::dev::IPidControlRaw>();
return p && (p->*fn)(type, offset, ref...);
return p && std::invoke(fn, p, type, offset, ref...);
}

template<typename T_refs>
Expand Down

0 comments on commit 3778720

Please sign in to comment.