c++ - Why Does C++1* Still Need the template Keyword in Lieu of Full Duck Typing -


many years ago, (at least me,) static c++ polymorphism seemed coherent. languages such python relied on duck typing, have:

def fn(foo, bar):     foo.baz(bar.bo()) 

and idea if "quacked" appropriately, fine language.

in c++, conversely, you'd have explain "animal" was:

void fn(foo_type foo, bar_type bar); 

and "kingdoms of families", you'd explicitly need use template keyword:

template<class foo, class bar> void fn(foo foo, bar bar); 

with new features auto ...() -> decltype return types, generic lambdas, there appears more non-template python-like duck typing:

[] (auto container) { return container.size(); }; 

my question, then, why template keyword still needed? why not embrace (optional) duck typing:

// takes foo_type , bar_type  void fn(foo_type foo, bar_type bar);  // takes "foo-quacking" type, , bar_type void fn(auto foo, bar_type bar);  // etc. 

it's @ door part of concepts feature, , compilers implement it! example, gcc 4.9, if specify -std=c++1y, can compile , run following:

auto print_arg(auto arg) {   std::cout << arg; } 

Comments

Popular posts from this blog

ios - UITEXTFIELD InputView Uipicker not working in swift -

Hatching array of circles in AutoCAD using c# -