SHARE
TWEET

Untitled

a guest Jun 18th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. template<typename T>
  2. class Dao {
  3.     public:
  4.     virtual T Create(T obj) = 0;
  5.     virtual T Upsert(T obj) = 0;
  6.     virtual void Delete(int id) = 0;
  7.     virtual T Get(int id) = 0;
  8.  
  9.     // This function is supposed to run any member function passed to it
  10.     // inside the future. The passed function can be either from the Dao
  11.     // class or one of its derived classes.
  12.     template <typename U, typename... Args>
  13.     std::future<U> RunAsync(U (Dao::*func)(Args...), Args... args){
  14.       return std::async(std::launch::async,func,this,args...);
  15.     }
  16. };
  17. class ModelDao : public Dao<Model> {
  18.    public:
  19.    // implementing the virtual functions
  20.    MyModel Foo(){ ... };
  21. };
  22. class Model { ... };
  23.      
  24. std::future<Model> f = dao.RunAsync(&Dao<Model>::Get, 100);
  25.      
  26. template argument deduction/substitution failed:
  27. mismatched types 'Dao<Model>' and 'ModelDao'
  28. 'Foo' is not a member of 'Dao<Model>'
  29.      
  30. ModelDao mDao;
  31. Model mModel;
  32. std::future<Model> f1 = mDao.RunAsync(&Dao::Create,mModel);
  33. std::future<void> f2 = mDao.RunAsync(&ModelDao::Foo);
  34. std::future<Model> f3 = mDao.RunAsync(&ModelDao::Create,mModel);
  35.      
  36. ModelDao mDao;
  37. std::future<Model> f = std::async(std::launch::async, &ModelDao::Get,&mDao,100);
  38. std::future2<void> f2 = std::async(std::launch::async [&](){mDao.Foo();});
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top