This question already has an answer here:
I'm working on a variant of std::function
. One thing I'd like to be able to do is to allow people to specify the function signature as Function<void() noexcept>
and have that only accept functors and function pointers that are noexcept callables.
I tried to do the following, but it didn't compile:
template<typename T>
struct Function;
template<typename R, typename... Args>
struct Function<R(Args...)> {};
template<typename R, typename... Args>
struct Function<R(Args...) noexcept> {};
How can I achieve the desired result? That the instantiation Function<void() noexcept>
is distinct from Function<void()>
.
One easy alternative I already know about is to just add on another template parameter, say template<typename T, bool IS_NOEXCEPT = false>
. I'd rather not do that. I'd rather have the syntax of Function<void() noexcept>
, not Function<void(), true>
.
Note: even if we are talking C++17, I'm pretty sure the is_nothrow_callable
type trait won't cut it.
Aucun commentaire:
Enregistrer un commentaire