Skip to content

Instantly share code, notes, and snippets.

@ArseniyShestakov
Last active February 3, 2018 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArseniyShestakov/2f273b81d60a570eb3813dd1695b122e to your computer and use it in GitHub Desktop.
Save ArseniyShestakov/2f273b81d60a570eb3813dd1695b122e to your computer and use it in GitHub Desktop.
Variadic test v2 (shared_ptr)
// g++ variadic.cpp -std=c++11
#include <iostream>
#include <vector>
#include <memory>
struct sOne
{
void one(int i)
{
std::cout << "one " << i << "\n";
}
};
struct sTwo
{
void two(int i)
{
std::cout << "two " << i << "\n";
}
};
struct testInt : public sOne, public sTwo { };
struct Base
{
std::vector<std::shared_ptr<testInt>> objects;
Base()
{
objects.push_back(std::make_shared<testInt>());
}
};
template<typename T, typename ... Args, typename ... Args2>
void call(Base * b, void (T::*ptr)(Args...), Args2 ...args)
{
for(auto & obj : b->objects)
((*obj).*ptr)(args...);
}
int main(void)
{
auto b = new Base();
call(b, &sOne::one, 10);
call(b, &sTwo::two, 20);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment