Assert that both C++ and Rust rules use the same generics#101
Conversation
| } | ||
|
|
||
| // Check that both source and target use the same generics. | ||
| for (unsigned i = 0; i < generics.size(); ++i) { |
There was a problem hiding this comment.
i = 0, e = generics.size(); i != e
|
|
||
| // Check that both source and target use the same generics. | ||
| for (unsigned i = 0; i < generics.size(); ++i) { | ||
| auto placeholder = std::format("T{}", i + 1); |
There was a problem hiding this comment.
instead of allocating memory on every generic for every rule, an alternative is to declare a global constant:
char generic_types[][] = ["T1", "T2", "T3", "T4"];
| char storage[kMaxGenerics][3]{}; | ||
|
|
||
| constexpr GenericPlaceholders() { | ||
| for (unsigned i = 0; i < kMaxGenerics; ++i) { |
There was a problem hiding this comment.
I meant a constant array, not this..
There was a problem hiding this comment.
It's a constexpr array with kMaxGeneric elements so that we don't get hard to debug errors when kMaxGeneric changes
There was a problem hiding this comment.
You can use an std::array if you want to make it safe. asserts aren't that need as it throws if you access OOB.
There was a problem hiding this comment.
Ok, I can use std::array, but the idea was not to manually write {"T1", "T2", "T3", ...}, but instead be generated automatically based on kMaxGenerics
There was a problem hiding this comment.
Done, I replaced with std::array
No description provided.