Replies: 2 comments 1 reply
|
Here's an example of CRTP in Cpp2: printer: <T> type = {
print: (this) = {
derived:= unsafe_cast<*const T>(this&);
name:= derived*.get_name();
std::cout << "The animal is a (name)$\n";
}
}
cat: type = {
this: printer<cat>;
get_name: (this) -> std::string = { return "cat"; }
}
dog: type = {
this: printer<dog>;
get_name: (this) -> std::string = { return "dog"; }
}
main: () -> int = {
c: cat = ();
d: dog = ();
c.print();
d.print();
return 0;
}There's also an open suggestion to implement a "deducing this" equivalent in Cpp2, which would simplify CRTP. @hsutter I found that this syntax |
1 reply
It is nice that you want to use cppfront for this. If this is more than an exploration project you should not use it. Cppfront is still in development and there are a lot of corner cases that do not work yet. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hello. I have placed a minimal example of CRTP here. I would like to know whether CPP2's Awesome Metafunction Powers ™ 🙂 (or any other powers) would enable it to do CRTP like this.
I didn't find any mention of CRTP by searching this repo. (Hope I didn't miss anything.)
Expected output:
If there are any difficulties with the Devanagari text (hope not) the Latin abbreviated alternates can be used instead and the output would be:
I am at the verge of seriously starting on a project, and would like to do it using CPP2 if possible, but CRTP is important for me…
All reactions