build in a catch-all to signal failure
this overload will be picked only if none of the more specific overloads is applicable. Instantiating this overload will then trigger a static assertion failure. This way we sort out impossible or dangerous combinations at compile time already. I found no simple way to include the actual type parameters in the generated error message (string concatenation at compiletime) The throw-statement is only there to prevent a warning due to missing return statement.
This commit is contained in:
parent
504ff07fc0
commit
c698d80a80
1 changed files with 13 additions and 0 deletions
|
|
@ -162,8 +162,21 @@ namespace util {
|
|||
|
||||
return AccessCasted<TAR>::access (*elem);
|
||||
}
|
||||
|
||||
|
||||
/** catch-all to signal failure of conversion */
|
||||
static TAR
|
||||
access (...)
|
||||
{
|
||||
// NOTE: if you see this assertion failure, none of the above predicates were true.
|
||||
// Chances are that you requested a conversion that is logically impossible or dangerous,
|
||||
// like e.g. taking a reference from an anonymous value parameter
|
||||
static_assert (!sizeof(TAR), "AccessCasted: No valid conversion or cast supported for these types.");
|
||||
throw error::Invalid("impossible or unsafe type conversion requested");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace util
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in a new issue