fork(1) download
  1. #include <type_traits>
  2. #include <string>
  3.  
  4. template <typename Heir>
  5. class SToString {
  6. public:
  7. std::string toString() {
  8. static_assert(std::is_member_function_pointer<decltype(&Heir::toStringImpl)>::value, "class derived from SToString should implement toStringImpl()");
  9. return static_cast<Heir*>(this)->toStringImpl();
  10. }
  11. };
  12.  
  13. class Foo : public SToString<Foo> {
  14. public:
  15. std::string toStringImplRRRRRRRRRRRRR() {
  16. return "Foo";
  17. }
  18. };
  19.  
  20. int main() {
  21. Foo f;
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0s 3292KB
stdin
Standard input is empty
stdout
Standard output is empty