Concepts? Template specialization depending on class functions?
Ben Phillips
Ben_member at pathlink.com
Thu Mar 2 08:04:09 PST 2006
I have a question and a suggestion:
Is it possible to determine whether a given class contains a specific member
function?
It would be useful to be able to create a template for classes that have certain
functions without
requiring the user to inherit from an interface. One idea I've heard is to use
"concepts" (a possible
extension to C++) where code would go as follows
concept Collection(T)
{
bool add(T t);
bool isEmpty();
..
}
template doSomething(CollectionType : Collection)
{
void doSomething(CollectionType t) { ... }
}
This would allow the compiler to give a clearer error message to people who try
to use the template
with a class that doesn't fit the Collection concept. Instead of errors about
undefined functions the user
would be told something like "Error: T does not fit the Collection concept [and
maybe list the missing
functions'".
More information about the Digitalmars-d
mailing list