Partial template specialization for more than one typename
Posted
by
Matt Joiner
on Stack Overflow
See other posts from Stack Overflow
or by Matt Joiner
Published on 2010-12-25T09:02:33Z
Indexed on
2010/12/25
10:54 UTC
Read the original article
Hit count: 259
In the following code, I want to consider functions (Op
s) that have void
return to instead be considered to return true
. The type Retval
, and the return value of Op
are always matching. I'm not able to discriminate using the type traits shown here, and attempts to create a partial template specialization based on Retval
have failed due the presence of the other template variables, Op
and Args
.
How do I specialize only some variables in a template specialization without getting errors? Is there any other way to alter behaviour based on the return type of Op
?
template <typename Retval, typename Op, typename... Args>
Retval single_op_wrapper(
Retval const failval,
char const *const opname,
Op const op,
Cpfs &cpfs,
Args... args) {
try {
CallContext callctx(cpfs, opname);
Retval retval;
if (std::is_same<bool, Retval>::value) {
(callctx.*op)(args...);
retval = true;
} else {
retval = (callctx.*op)(args...);
}
assert(retval != failval);
callctx.commit(cpfs);
return retval;
} catch (CpfsError const &exc) {
cpfs_errno_set(exc.fserrno);
LOGF(Info, "Failed with %s", cpfs_errno_str(exc.fserrno));
}
return failval;
}
© Stack Overflow or respective owner