17 Ocak 2019 Perşembe

requires Anahtar Kelimesi

Giriş
C++20 ile geliyor. requires constaint ve requires expression diye iki farklı kavram var.
Açıklaması şöyle
A requires constraint does not have to use a requires expression. It can use any more-or-less arbitrary boolean constant expression. Therefore, requires (foo) must be a legitimate requires constraint.

A requires expression (that thing that tests whether certain things follow certain constraints) is a distinct construct; it's just introduced by the same keyword. requires (foo f) would be the beginning of a valid requires expression.
Örnek - expression
Açıklaması şöyle.
requires-expression can also be used in a requires-clause ([temp]) as a way of writing ad hoc constraints on template arguments
The first requires introduces the requires-clause, and the second introduces the requires-expression.
Şöyle yaparız.
template<typename T>
  requires requires (T x) { x + x; }
    T add(T a, T b) { return a + b; }

Hiç yorum yok:

Yorum Gönder