Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename T>
- class Dao {
- public:
- virtual T Create(T obj) = 0;
- virtual T Upsert(T obj) = 0;
- virtual void Delete(int id) = 0;
- virtual T Get(int id) = 0;
- // This function is supposed to run any member function passed to it
- // inside the future. The passed function can be either from the Dao
- // class or one of its derived classes.
- template <typename U, typename... Args>
- std::future<U> RunAsync(U (Dao::*func)(Args...), Args... args){
- return std::async(std::launch::async,func,this,args...);
- }
- };
- class ModelDao : public Dao<Model> {
- public:
- // implementing the virtual functions
- MyModel Foo(){ ... };
- };
- class Model { ... };
- std::future<Model> f = dao.RunAsync(&Dao<Model>::Get, 100);
- template argument deduction/substitution failed:
- mismatched types 'Dao<Model>' and 'ModelDao'
- 'Foo' is not a member of 'Dao<Model>'
- ModelDao mDao;
- Model mModel;
- std::future<Model> f1 = mDao.RunAsync(&Dao::Create,mModel);
- std::future<void> f2 = mDao.RunAsync(&ModelDao::Foo);
- std::future<Model> f3 = mDao.RunAsync(&ModelDao::Create,mModel);
- ModelDao mDao;
- std::future<Model> f = std::async(std::launch::async, &ModelDao::Get,&mDao,100);
- std::future2<void> f2 = std::async(std::launch::async [&](){mDao.Foo();});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement