Lite Concepts is a “limitation” of part of the complete concept design for C ++. This is described in detail in the N3701 "Concepts Lite" . Chapter 2 is a short tutorial that quickly goes through the basic principles and their applications, which is great for people who don't want to read all 56 pages.
Lite concepts will not be part of C ++ 14, they will be released as a separate Technical Specification at the end of this year. The latest draft for the wording of TS is N3929 Lite Literature .
There are several different syntax options for constraints. Example code that Herb used in a conversation:
auto mean(const Sequence& seq) { auto n = 0.0; for (auto x : seq) n += x; return n / seq.size(); }
referred to as “short syntax” because it is the shorter equivalent of detailed syntax:
template <typename __T> requires Sequence<__T>() auto mean(const __T& seq) { auto n = 0.0; for (auto x : seq) n += x; return n / seq.size(); }
Both of them indicate that the mean function template can be created by any type that models the concept of Sequence . For simplicity, suppose that the requirements for Sequence are just what we need to implement mean : (a) the begin and end members that return iterators, and (b) the size member function that returns some kind of integral type. We could define the concept as:
template <typename T> concept bool Sequence() { return requires(T t) { {t.size()} -> Integral; {t.begin()} -> InputIterator; {t.end()} -> InputIterator; requires Same<decltype(t.begin()), decltype(t.end())>(); } }
assuming straightforward definitions of Integral , InputIterator and Same . This definition of the concept ensures that for some invented value t test type t :
t.size() is a valid expression and returns a type that models the concept of Integral .t.begin() valid and returns a type that models the InputIterator .- The same goes for
t.end() . InputIterator returned by t.begin() is of the same type as t.end() returned.
Casey source share