Skip to content
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

Add registerCallback() overload to grabbers to support assignment of boost::functions with templated signatures #3128

Merged

Conversation

SergioRAgostinho
Copy link
Member

Design to support callback registration from boost::function objects.

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

#include <functional>
#include <iostream>
#include <typeinfo>

struct Grabber
{
  std::set<std::string> registered_types_;

  template<typename T, template<typename> class FunctionT>
  [[deprecated ("Bind the callback to a std::function.")]] void
  registerCallback (const FunctionT<T>& cb)
  {
    registerCallback<T> (std::function<T> (cb));
  }

  template<typename T> void
  registerCallback (const std::function<T>& cb)
  {
    registered_types_.insert (typeid (T).name ());
  }
};


using Sig = void (int);

void
number (int n1, int n2)
{
  std::cout << "I am number " << n1 << " and " << n2 << std::endl;
}

int
main()
{
  boost::function<Sig> bf = boost::bind (number, _1, 2);
  std::function<Sig> sf = bf;

  auto lambda = [] (int n1) { return number (n1, 2); };

 
  Grabber gb;

 

  // FunctionT<T>
  gb.registerCallback (bf); // triggers deprecation warning
  gb.registerCallback (sf);
  // gb.registerCallback (boost::bind (number, _1, 2)); // doesn't compile
  gb.registerCallback<Sig> (boost::bind (number, _1, 2));
  // gb.registerCallback (std::bind (number, std::placeholders::_1, 2)); // doesn't compile
  gb.registerCallback<Sig> (std::bind (number, std::placeholders::_1, 2));
  // gb.registerCallback (lambda); // Doesn't compile
  gb.registerCallback<Sig> (lambda);
  return 0;
}

@SergioRAgostinho SergioRAgostinho added c++14 module: io changelog: deprecation Meta-information for changelog generation labels Jun 6, 2019
io/include/pcl/io/grabber.h Outdated Show resolved Hide resolved
@taketwo taketwo merged commit 575a9b9 into PointCloudLibrary:master Jun 6, 2019
@SergioRAgostinho SergioRAgostinho mentioned this pull request Jun 6, 2019
11 tasks
@SergioRAgostinho SergioRAgostinho deleted the function-grabber branch June 7, 2019 08:09
@taketwo taketwo changed the title Add registerCallback overload to pcl grabber to support assignment of boost functions with templated signatures Add registerCallback overload to grabbers to support assignment of boost functions with templated signatures Jan 14, 2020
@taketwo taketwo changed the title Add registerCallback overload to grabbers to support assignment of boost functions with templated signatures Add registerCallback overload to grabbers to support assignment of boost::functions with templated signatures Jan 18, 2020
@taketwo taketwo changed the title Add registerCallback overload to grabbers to support assignment of boost::functions with templated signatures Add registerCallback() overload to grabbers to support assignment of boost::functions with templated signatures Jan 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: deprecation Meta-information for changelog generation module: io
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants