fork download
  1. #include <string>
  2. #include <map>
  3. #include <iostream>
  4.  
  5. template <class T, class Factory> class add_ctor {
  6. public:
  7. template<Args...> add_ctor<Args&&...> : obj(Factory()(std::forward<Args>(args)...)) {}
  8. private:
  9. T* obj;
  10. };
  11.  
  12. class A {
  13. public:
  14. std::string v;
  15. static A createOne();
  16. private:
  17. A();
  18. };
  19. A A::createOne() {
  20. A a;
  21. a.v = "Hello!";
  22. return a;
  23. }
  24.  
  25. int main() {
  26. std::map<int, add_ctor<A, &A::createOne()> > as;
  27. std::cout << as[0].v << "\n";
  28. return 0;
  29. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:7:18: error: 'Args' has not been declared
prog.cpp:7:36: error: 'Args' was not declared in this scope
prog.cpp:7:42: error: expected parameter pack before '...'
prog.cpp:7:45: error: wrong number of template arguments (1, should be 2)
prog.cpp:5:41: error: provided for 'template<class T, class Factory> class add_ctor'
prog.cpp:7:47: error: expected unqualified-id before ':' token
prog.cpp: In function 'int main()':
prog.cpp:26:46: error: template argument 2 is invalid
prog.cpp:26:48: error: template argument 2 is invalid
prog.cpp:26:48: error: template argument 4 is invalid
prog.cpp:26:52: error: invalid type in declaration before ';' token
prog.cpp:27:22: error: invalid types 'int[int]' for array subscript
stdout
Standard output is empty