Do nonmember nonfriend functions improve genericity?

B

bluekite2000

The author's reason is "because its hard to write templates that dont
know whether or not an operation is a member for a given type". What
does he mean by this? An example is appreciated.
 
V

Victor Bazarov

The author's

The author of what?
> reason is "because its hard to write templates that dont
know whether or not an operation is a member for a given type". What
does he mean by this? An example is appreciated.

What is the context?

If I had to speculate, the "author" you're quoting (?) speaks of template
code similar to

template<class T> void foo(T t)
{
// if T has a member 'bar', use it
t.bar();
// else, don't use it, use some global function
::bar(t);
}

Such template is rather difficult to implement, but possible, using SFINAE
technique. Look up "has_member" in the archives.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top