Search code examples
c++templates

What is this C++ template feature called?


From within a template function or class, you can call a function on an object of the template parameter T like so:

template<typename T>
void call_foo_on_t(T t) {
  t.foo();
}

This means you can pass in any type as T that has defines the function foo().

Does this feature/pattern have a "formal" name?

I've tried to search for it but without luck - it's kind of hard to describe in a short enough way for search engines to pick it up.


Solution

  • Does this feature/pattern have a "formal" name?

    No it doesn't have a formal name in the c++ standard.

    The term that is applicable for this is duck typing.