Talk:Constrained genericity: Difference between revisions
→The moved section: fixed an error in the code
(→C++ example, concepts and C++0x: Code moved to discussion page because concepts were voted out of C++) |
(→The moved section: fixed an error in the code) |
||
Line 44:
concept_map Eatable<T>
{
void eat(T const& t) { t
}</lang>
The difference to a global function <tt>void eat(Food const&)</tt> is that the function in the concept map is only visible to functions using that concept, thus reducing namespace polution. Functions directly operating on <tt>Food</tt> objects can use the interface provided by <tt>Food</tt> itself, e.g. <tt>apple.munch()</tt>, or explicitly invoke <tt>Eatable<Food>::eat(apple)</tt>. Of course, concept maps also work with built-in types:
|