fork download
  1. #include <memory> // for unique_ptr.
  2. #include <type_traits>
  3.  
  4.  
  5. template<typename value_type>
  6. class unko
  7. {
  8. public:
  9. unko(value_type const &val) : sumapo{ new value_type{ val } } {}
  10.  
  11. auto get() const -> value_type &
  12. {
  13. return *this->sumapo.get();
  14. }
  15.  
  16. auto get() -> value_type &
  17. {
  18. static_assert(!std::is_const<value_type>::value, "kuso shite nero(unko must be const)");
  19. return *this->sumapo.get();
  20. }
  21.  
  22. private:
  23. std::unique_ptr<value_type> sumapo;
  24. };
  25.  
  26. auto main() -> int
  27. {
  28. {
  29. unko<int> a{ 20 }; int &i1 = a.get();
  30. unko<int> const b{ 20 }; int &i2 = b.get();
  31. // unko<int const> c{ 20 }; int const &i3 = c.get();
  32. unko<int const> const d{ 20 }; int const &i4 = d.get();
  33. }
  34. }
  35.  
Success #stdin #stdout 0s 3424KB
stdin
Standard input is empty
stdout
Standard output is empty