有没有统一函数类型限定符和简化可恶的函数类型的建议?
Is there any proposal to uniformize function type qualifiers and simplify abominable function types?
abominable function types combinatory can be a real pain when dealing with template based on function type matching (see std::is_function).
包括 const、volatile、&、&&、noexcept(加上可变参数支持)在内的其他限定符可能会导致大量模板特化。
但是,noexcept
说明符允许使用布尔表达式 noexcept(expr)
:
noexcept
相当于默认的 noexcept(true)
所以,在未来,我们可以想象用这个模型来统一所有限定符:
const
限定符等同于 const(true)
volatile
限定符将等同于 volatile(true)
&
限定符将等同于 &(true)
&&
限定符将等同于 &&(true)
而且,锦上添花,使预选赛可扣除,以便能够写出类似的东西:
template <typename Fn>
struct function_traits;
template <typename R, bool CQ, bool VQ, bool LVRQ, bool RVRQ, bool NEQ, ARGS... Args>
struct function_traits<R(Args...) const(CQ) volatile(VQ) &(LVRQ) &&(RVRQ) noexcept(NEQ)>
{
static constexpr bool is_const_qualified = CQ;
static constexpr bool is_volatile_qualified = VQ;
static constexpr bool is_lvalue_ref_qualified = LVRQ;
...
};
我想听听关于此类问题的任何想法。
abominable function types combinatory can be a real pain when dealing with template based on function type matching (see std::is_function).
包括 const、volatile、&、&&、noexcept(加上可变参数支持)在内的其他限定符可能会导致大量模板特化。
但是,noexcept
说明符允许使用布尔表达式 noexcept(expr)
:
noexcept
相当于默认的noexcept(true)
所以,在未来,我们可以想象用这个模型来统一所有限定符:
const
限定符等同于const(true)
volatile
限定符将等同于volatile(true)
&
限定符将等同于&(true)
&&
限定符将等同于&&(true)
而且,锦上添花,使预选赛可扣除,以便能够写出类似的东西:
template <typename Fn>
struct function_traits;
template <typename R, bool CQ, bool VQ, bool LVRQ, bool RVRQ, bool NEQ, ARGS... Args>
struct function_traits<R(Args...) const(CQ) volatile(VQ) &(LVRQ) &&(RVRQ) noexcept(NEQ)>
{
static constexpr bool is_const_qualified = CQ;
static constexpr bool is_volatile_qualified = VQ;
static constexpr bool is_lvalue_ref_qualified = LVRQ;
...
};
我想听听关于此类问题的任何想法。