简体   繁体   中英

Is there any proposal to uniformize function type qualifiers and simplify abominable function types?

The abominable function types combinatory can be a real pain when dealing with template based on function type matching (see std::is_function ).

Miscellaneous qualifers including const, volatile, &, &&, noexcept (plus the variadic arguments support) may lead to a large number of template specializations.

However, the noexcept specifier allows to use a boolean expression noexcept(expr) :

  • noexcept being equivalent to noexcept(true) as default

So, in a future, can we imagine to uniformize all qualifers with this model:

  • const qualifier will be equivavent to const(true)
  • volatile qualifier will be equivavent to volatile(true)
  • & qualifier will be equivavent to &(true)
  • && qualifier will be equivavent to &&(true)

And, the icing on the cake, make qualifiers deductible to be able to write something like:

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;
    ...
};

I would like to hear any thoughts about such issues.

I made a similar suggestion on the std-proposals mailing list previously. See threads here and here .

The conclusion from this discussion was that adding such a feature to the language would be a lot of work. Not only would it be necessary to add rules to the language for deducing the boolean arguments to the qualifiers, but there would also be many other issues such as the point at which the qualifiers are instantiated and evaluated. A proposal of this size would also be likely to introduce many other issues that would have to be hammered out.

Gašper Ažman appeared to believe that some form of "computed deduction" would be an alternative solution to the problem that would be more feasible. If you're interested in helping with this effort then I would suggest contacting him.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM