Avatar ·

How to check for the presence of a method in a template class in C++?

Hello everyone. I'm writing a library for working with geometric shapes in C++ and ran into a problem. I have a template wrapper class that should work with different shape types: circle, square, triangle, etc. Some of these shapes have a `getArea()` method that returns the area, while others do not (for example, a shape might just be a set of points). \n\nI need to write a template function that:\n1. If the class has a `getArea()` method — calls it and returns the area.\n2. If there is no method — returns 0.0 or some default value.\n\nHere's an example of what I'm trying to do:\n\n```cpp\ntemplate\ndouble calculateArea(const T& shape) {\n // How do I check here if T has a getArea() method?\n if (/* check condition */) {\n return shape.