fork(1) download
  1. #include <iostream>
  2. #include <utility>
  3. using namespace std;
  4.  
  5. template<typename X>
  6. struct thing {
  7. };
  8.  
  9.  
  10. template<typename> struct traits {};
  11. template<
  12. template<class>class T,
  13. typename A>
  14. struct traits<T<A>> {
  15. using param = A;
  16. template<typename X>
  17. using templ = T<X>;
  18. };
  19.  
  20.  
  21. template<typename Y>
  22. decltype (auto) g(Y&& t) {
  23. // This is ugly, but well ...
  24. using trait = traits<typename std::remove_reference<Y>::type>;
  25. using A = typename trait::param;
  26. // using it, not as simple as T<A>, but at least it works
  27. typename trait::template templ<A> copy{t};
  28. typename trait::template templ<void> other;
  29. A data;
  30. return std::forward<Y>(t);
  31. }
  32.  
  33. int main(int, char**) {
  34. thing<int> it {};
  35. g(thing<int> {});
  36. g(it);
  37. return 0;
  38. }
Success #stdin #stdout 0s 3408KB
stdin
Standard input is empty
stdout
Standard output is empty