Last active
February 3, 2018 15:35
-
-
Save ArseniyShestakov/2f273b81d60a570eb3813dd1695b122e to your computer and use it in GitHub Desktop.
Variadic test v2 (shared_ptr)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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