#include <cstddef>
template <typename T, std::size_t MaxElements>
struct circular_buffer{};
template <typename circular_buffer>
bool operator==(const circular_buffer &a, const circular_buffer &b) {
return true;
}
int main() {
circular_buffer<int, 2> a;
circular_buffer<int, 3> b;
a == b;
return 0;
}
This code is work only for 2==3. But my 2 != my 3. Help me to repair operator.
circular_buffershouldn't be a template parameter to your operator. That operator is worthless as is. Beyond that, do you understand that by specifying two different sizes you actually have two different end concrete types? One iscircular_buffer<int,2>, the other iscircular_buffer<int,3>. They're not the same type. What is it you hope to achieve with youroperator ==when that happens (or for that matter, in general)?template <typename circular_buffer>name is arbitrary, and currently just hide (for the function) the template class with the same name. So it is misleading.