{"id":334986,"date":"2022-06-25T15:00:20","date_gmt":"2022-06-25T15:00:20","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=334986"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=334986","title":{"rendered":"<span>\u041a\u043e\u043d\u0446\u0435\u043f\u0442\u044b \u0438 \u043c\u043e\u0434\u0443\u043b\u0438 cpp. \u0412\u0437\u0433\u043b\u044f\u0434 \u0441o \u0441\u0442\u043e\u0440\u043e\u043d\u044b undefined \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 2002 \u0433\u043e\u0434\u0443 \u0410\u043b\u0435\u043a\u0441 \u0410. \u0421\u0442\u0435\u043f\u0430\u043d\u043e\u0432 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442 \u043b\u0435\u043a\u0446\u0438\u044e \u0432 \u0430\u0434\u043e\u0431\u0438: STL and Its Design Principles &#8212; \u0433\u0434\u0435 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u043a\u0435\u0439\u0432\u043e\u0440\u0434 concept (\u0442\u0430\u043c \u043f\u0440\u044f\u043c \u0446\u0435\u043b\u044b\u0439 \u0441\u043b\u0430\u0439\u0434 \u043f\u0440\u043e \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u044b). \u0412 2009 \u0433\u043e\u0434\u0443 \u0432 \u0441\u0432\u0435\u0442 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u043a\u043d\u0438\u0433\u0430 Elements of programming (Stepanov, McJones) \u0438 \u0433\u0434\u0435 \u043f\u043e-\u043c\u043e\u0435\u043c\u0443 \u043d\u0435\u0442 \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0431\u0435\u0437 \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u043e\u0432. \u0412 2011 \u043d\u043e\u0432\u044b\u0439 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442 \u044f\u0437\u044b\u043a\u0430 \u0441++11, \u0433\u0434\u0435 \u0432 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 (\u043f\u0440\u044f\u043c \u043e\u0447\u0435\u043d\u044c \u0436\u0430\u043b\u044c) \u0444\u0438\u0447\u0430\u0445 \u0444\u0438\u0433\u0443\u0440\u0438\u0440\u0443\u044e\u0442 \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u044b. \u0412 2014 \u043c\u0438\u0440 \u0432\u0438\u0434\u0438\u0442 \u0442\u0432\u043e\u0440\u0435\u043d\u044c\u0435 \u0421\u0442\u0440\u0430\u0443\u0441\u0442\u0440\u0443\u043f\u0430 &#8212; Tour of C++, \u0433\u0434\u0435 \u0433\u043b\u0430\u0432\u0430 5.4 \u043d\u0430\u0437\u0432\u0430\u043d\u0430 Concepts and Generic Programming, \u0445\u043e\u0442\u044f \u044f\u0437\u044b\u043a \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043a\u0435\u0439\u0432\u043e\u0440\u0434 concept. \u0413\u043e\u0434\u043e\u043c \u0440\u0430\u043d\u0435\u0435, \u0432 2013, \u0410\u043d\u0434\u0440\u044e \u0421\u0430\u0442\u0442\u043e\u043d \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 \u0431\u0443\u043c\u0430\u0433\u0443 Concepts Lite. \u0412 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0435 \u0441++14 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u0430\u044f \u0444\u0438\u0447\u0430 digit separators, \u043d\u043e \u043d\u0435\u0442 \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u043e\u0432. \u0412 2017 \u043d\u0430 \u0440\u0435\u0434\u0434\u0438\u0442\u0435 \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u044e\u0442 c++17 \u0438 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e\u0442 \u043e\u0442\u0434\u043e\u0445\u043d\u0443\u0442\u044c \u0435\u0449\u0435 \u0442\u0440\u0438 \u0433\u043e\u0434\u0430.<\/p>\n<p>\u0427\u0435\u0440\u0435\u0437 \u0442\u0440\u0438 \u0433\u043e\u0434\u0430 \u0441\u043e\u0447\u0443\u0432\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 html \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0437\u0430\u0445\u043e\u0447\u0435\u0442 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u044f\u0437\u044b\u043a \u0441 \u0447\u0438\u0441\u0442\u043e\u0433\u043e \u043b\u0438\u0441\u0442\u0430, \u0437\u0430\u044e\u0437\u0430\u0432 \u0438 \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u044b, \u0438 \u043c\u043e\u0434\u0443\u043b\u0438. \u041c\u043e\u0434\u0443\u043b\u0438 \u043f\u0440\u0438\u0432\u043d\u043e\u0441\u044f\u0442 \u0432\u0430\u0436\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e &#8212; \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u0418\u0434\u0435\u044f \u0432 \u0448\u0430\u0433 \u0437\u0430 \u0448\u0430\u0433\u043e\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0438 \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0438\u0445 \u043f\u043e\u0441\u043b\u0435 \u0432 \u043d\u0435\u0447\u0442\u043e \u043e\u0441\u043e\u0437\u043d\u0430\u043d\u043e\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043b\u0438\u043d\u0442\u0435\u0440.<\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e print:<\/p>\n<pre><code class=\"cmake\">\/\/ guard for non-printable types template&lt;typename T, typename... Ts> void print(const T&amp; x, const Ts&amp;...) {   auto msg = \"\\n[error] not supported print operation for type \";   std::cout &lt;&lt; msg &lt;&lt; typeid(x).name() &lt;&lt; \"\\n\"; }  \/\/ print first arg and continue with rest template&lt;Printable T, typename... Ts> void print(const T&amp; x, const Ts&amp;... rest) { ... }<\/code><\/pre>\n<p>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0434\u043b\u044f \u043c\u0430\u0442\u0447\u0438\u043d\u0433\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043b\u0438\u043d\u0442\u0435\u0440\u0430 (javascript \u043a\u043e\u0434\u0430) \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442\u044c \u043a\u0430\u043a-\u0442\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cmake\">\/\/ checking for pair of quotes, while skipping whats inside them template&lt;InputIterator I> constexpr result_t lint(...) {     auto pred = [](char ch){ return ch == '\\'' || ch == '\"'; };     ... }<\/code><\/pre>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0432\u044b\u0448\u0435 constexpr, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u0435\u0441\u0442\u044b \u043d\u0430 \u043a\u0430\u0436\u0434\u0443\u044e! \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044e \u043c\u043e\u0434\u0443\u043b\u044f:<\/p>\n<pre><code class=\"cmake\">constexpr auto test(const std::string_view str) {    auto p = std::make_pair(std::begin(str), std::end(str));    return !lint(..., p) &amp;&amp; p.first == p.second; }  static_assert(test(\"'foo'\"), \"single quoted string test\"); static_assert(test(\"'\\\\' quoted'\"), \"string with escaped single quote test\");<\/code><\/pre>\n<p>\u0423 \u043b\u0438\u043d\u0442\u0435\u0440\u0430, \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0432\u044b\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441:<\/p>\n<pre><code class=\"cmake\">result_t lint(..., \/* pairs of iterators *\/) { }<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0438\u0434\u0435\u044f \u0432\u043f\u043e\u043b\u043d\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0430\u044f: \u043c\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c. \u041c\u043e\u0436\u0435\u043c \u0440\u0435\u0448\u0438\u0442\u044c \u0435\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f, \u0430 \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0438\u0434\u0435\u044e \u0438\u0437 \u0432\u0438\u0434\u0435\u043e Better Code: Runtime Polymorphism (Sean Parent) &#8212; \u0432 \u0434\u0432\u0443\u0445 \u0441\u043b\u043e\u0432\u0430\u0445, \u0442\u043e\u0442 \u0436\u0435 \u0441\u0430\u043c\u044b\u0439 \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c, \u043d\u043e \u0443\u0434\u043e\u0431\u043d\u0435\u0435 (e.g. extension of built-in types). \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c:<\/p>\n<pre><code class=\"cmake\">struct keyword_t { std::size_t id; }; template&lt;InputIterator I> constexpr result_t lint(const keyword_t&amp; x, matcher&lt;I>&amp; m) { ... }  \/\/ models forall relation \/\/ if at least one fails -> all fail template &lt;InputIterator I> constexpr result_t lint(const std::vector&lt;linter>&amp; xs, matcher&lt;I>&amp; m) { ... }<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0442\u0438\u043f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u0432\u0442\u043e\u0440\u043e\u0439 &#8212; \u043e\u0431\u0435\u0440\u0442\u043a\u0430 \u043d\u0430\u0434 \u043f\u0430\u0440\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432. \u041e\u0431\u0435\u0440\u0442\u043a\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"cmake\">template &lt;InputIterator I>  struct matcher {     I first;      I last;     constexpr matcher(I first, I last) : first{first}, last{last} {}      \/\/ advance 'first' while predicate is hold     template &lt;Predicate&lt;value_t> Op>     constexpr void skip(Op pred) {         first = std::find_if_not(first, last, std::move(pred));     }     ...<\/code><\/pre>\n<p>\u0415\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u0442\u0438\u043f\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f result_t. \u0423 \u043b\u0438\u043d\u0442\u0435\u0440\u0430 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0438, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f: \u0438\u043b\u0438 \u043c\u044b \u043d\u0430\u0448\u043b\u0438 \u043d\u0435\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435, \u0438\u043b\u0438 \u0432\u0441\u0435 \u043e\u043a. \u041f\u043e \u0438\u0434\u0435\u0435, \u0432\u044b\u0431\u043e\u0440 \u043f\u0430\u0434\u0430\u0435\u0442 \u043d\u0430 bool, \u043d\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0435\u043d \u043b\u0438\u043d\u0442\u0435\u0440 \u0447\u0443\u0442\u044c-\u0447\u0443\u0442\u044c \u043f\u043e\u0443\u043c\u043d\u0435\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 std::optional\\&lt;std::size_t\\>. \u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u043e\u043a, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043f\u0443\u0441\u0442\u043e\u0439 \u043e\u043f\u0448\u0438\u043e\u043d\u0430\u043b, \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 &#8212; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u043d\u043d\u044b\u0445 \u0448\u0430\u0433\u043e\u0432 \u0434\u043e \u043d\u0435\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043b\u0438\u043d\u0442\u0435\u0440 \u043d\u0430\u0448\u0435\u043b \u043d\u0435\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d \u0438\u043b\u0438 \u043d\u0435 \u043d\u0430\u0448\u0435\u043b \u0438\u0441\u043a\u043e\u043c\u044b\u0439, \u043a\u0438\u0434\u0430\u0435\u043c \u044d\u043a\u0441\u0435\u043f\u0448\u043d:<\/p>\n<pre><code class=\"cmake\">struct panic_t { }; template &lt;InputIterator I> constexpr result_t lint(const panic_t&amp;, matcher&lt;I>&amp; m) {     return 0         ? result_t{}         : throw std::domain_error(\"\\n err near \\n-> \" + m.debug_info()); }  struct iff_t { linter a; linter b; }; \/\/ models relation between pair of linters \/\/ if linter 'a' not fails, linter 'b' must not fail template &lt;InputIterator I> constexpr result_t lint(const iff_t&amp; x, matcher&lt;I>&amp; m) {     auto lhs = lint(x.a, m);     if (lhs.has_value()) return lhs;     auto rhs = lint(x.b, m);     return rhs.has_value() ? lint(panic_t{}, m) : result_t{}; }<\/code><\/pre>\n<p>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043d\u0430\u0448\u0435\u0433\u043e \u043b\u0438\u043d\u0442\u0435\u0440\u0430 \u0437\u0430\u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c (\u0438\u043b\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u043e\u0432\u0430\u0442\u044c), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0430\u0440\u0443\/\u0442\u0440\u043e\u0439\u043a\u0443 \u0441\u0432\u044f\u0437\u0443\u044e\u0449\u0438\u0445:<\/p>\n<pre><code class=\"cmake\">struct or_t { linter a; linter b; }; template &lt;InputIterator I> constexpr result_t lint(const or_t&amp; x, matcher&lt;I>&amp; m) {     return lint(x.a, m) ? lint(x.b, m) : result_t{}; }  struct optional_t { linter a; }; template &lt;InputIterator I> constexpr result_t lint(const optional_t&amp; x, matcher&lt;I>&amp; m) {     lint(x.a, m);     return {}; }  \/\/ models forall relation \/\/ if at least one fails -> all fail template &lt;InputIterator I> constexpr result_t lint(const std::vector&lt;linter>&amp; xs, matcher&lt;I>&amp; m) {     for (const auto&amp; x : xs) {         auto r = lint(x, m);         if (r.has_value()) return r;     }     return {}; }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a \u0440\u0430\u0437\u0431\u043e\u0440\u043a\u0435 (&#171;\u043b\u0438\u043d\u0442\u0438\u043d\u0433\u0443&#187;) javascript \u043a\u043e\u0434\u0430. \u0425\u0435\u0434\u0435\u0440\u044b (\u0438\u043b\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u044b) javascript \u0444\u0430\u0439\u043b\u043e\u0432 \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"typescript\">import * as foo from \"..\/foo\" import bar, { boo, kung as fu, mu } from \"..\/bar\";<\/code><\/pre>\n<p>\u0413\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0430 \u0445\u0435\u0434\u0435\u0440\u043e\u0432 \u0442\u0443\u0442: <a href=\"https:\/\/262.ecma-international.org\/6.0\/#sec-imports\" rel=\"noopener noreferrer nofollow\">https:\/\/262.ecma-international.org\/6.0\/#sec-imports<\/a> .<br \/> \u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0434\u043b\u044f \u0445\u0435\u0434\u0435\u0440\u043e\u0432 import_t \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u0432\u0441\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0448\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b:<\/p>\n<pre><code class=\"cmake\">struct import_t{}; template&lt;InputIterator I> result_t lint(const import_t&amp;, matcher&lt;I>&amp; m) { ... }<\/code><\/pre>\n<p>\u0412\u043d\u0443\u0442\u0440\u0438 \u0445\u043e\u0442\u044f \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 (\u0442\u0443\u0442 \u043f\u0440\u044f\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c, \u0447\u0442\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0435 \u0431\u0435\u0437 \u0432\u0441\u044f\u043a\u0438\u0445 while \u0438 for-loop \ud83d\ude42<\/p>\n<pre><code class=\"cmake\">\/\/ match: * as foo auto namespace_import = iff_t{     char_t{context::Chars::Star},     std::vector&lt;linter>{         keyword_t{context::Keywords::As},         identifier_t{}     } };  \/\/ match: { foo, bar as boo, ... } auto named_import = iff_t{     char_t{context::Chars::LeftCurlyBracket},     std::vector&lt;linter>{         optional_t{import_var_list_t{}},         char_t{context::Chars::RightCurlyBracket},     } };  \/\/ match: foo | foo, * as bar | foo, { bar... } auto imported_default_binding = std::vector&lt;linter>{     identifier_t{},     optional_t {         iff_t {             char_t{context::Chars::Comma},             or_t{                 namespace_import,                 named_import             }         }     } };  \/\/ and combining all togather  auto rule = iff_t{     keyword_t{ context::Keywords::Import },     or_t{         std::vector&lt;linter>{             string_t{},             optional_t{char_t{context::Chars::Semicolon}},         },         std::vector&lt;linter>{             or3_t {                 namespace_import,                 named_import,                 imported_default_binding,             },             keyword_t{context::Keywords::From},             string_t{},             optional_t{char_t{context::Chars::Semicolon}},         }     } };<\/code><\/pre>\n<p>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 import_t \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u0443\u0435\u0442 \u0433\u0440\u0430\u0444. \u0415\u0441\u043b\u0438 \u0432 \u0433\u0440\u0430\u0444\u0430\u0445 \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0438 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0446\u0438\u043a\u043b, \u0443\u043d\u043e\u0441\u0438\u043c \u0435\u0433\u043e \u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0434\u043e\u0431\u0438\u0432\u0430\u0435\u043c\u0441\u044f direct acyclic graph. \u041f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0446\u0438\u043a\u043b\u0430 \u0435\u0441\u0442\u044c \u0442\u043e\u043a\u0435\u043d import_var_list_t \u0432\u044b\u0448\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u0430\u0442\u0447\u0438\u0442 { foo, bar, &#8230;}, \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0442\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0442\u043e\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044e.<\/p>\n<p>\u041a\u0430\u043a-\u0442\u043e \u043d\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u0438\u0441\u0430\u0442\u044c, \u0442\u0430\u043a \u043a\u0430\u043a \u043b\u0438\u043d\u0442\u0435\u0440 \u0435\u0449\u0435 \u043e\u0439 \u043a\u0430\u043a \u0434\u0430\u043b\u0435\u043a \u043e\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f. \u0425\u043e\u0447\u0435\u0442\u0441\u044f \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u043a\u043d\u0438\u0433\u0443 JavaScript: The Good Parts (Douglas Crockford, 8 May 2008), \u043a\u043e\u0442\u043e\u0440\u0430\u044f, \u043a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f, \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u044e\u0437\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e &#171;\u0445\u043e\u0440\u043e\u0448\u0438\u0439&#187; \u0441\u0430\u0431\u0441\u0435\u0442 \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0438 \u0438\u0437 &#171;\u044f\u0432\u0430\u0441\u043a\u0440\u0438\u043f\u0442\u0430&#187;. \u041d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u0441\u0430\u0431\u0441\u0435\u0442 \u0431\u0443\u0434\u0435\u0442 \u0435\u0449\u0435 \u043c\u0435\u043d\u044c\u0448\u0435 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, for-loop, while &#8212; \u043d\u0435\u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u044b; var, let \u0437\u0430\u043f\u0440\u0435\u0449\u0435\u043d\u043d\u044b), \u0442\u043e \u0435\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e \u0438 \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u043b\u0438\u043d\u0442\u0435\u0440\u0430 \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043d\u0435 \u0442\u0430\u043a\u0430\u044f \u0443\u0436 \u043d\u0435\u043f\u043e\u0441\u0438\u043b\u044c\u043d\u0430\u044f.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/673388\/\"> https:\/\/habr.com\/ru\/post\/673388\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 2002 \u0433\u043e\u0434\u0443 \u0410\u043b\u0435\u043a\u0441 \u0410. \u0421\u0442\u0435\u043f\u0430\u043d\u043e\u0432 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442 \u043b\u0435\u043a\u0446\u0438\u044e \u0432 \u0430\u0434\u043e\u0431\u0438: STL and Its Design Principles &#8212; \u0433\u0434\u0435 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442 \u043a\u0435\u0439\u0432\u043e\u0440\u0434 concept (\u0442\u0430\u043c \u043f\u0440\u044f\u043c \u0446\u0435\u043b\u044b\u0439 \u0441\u043b\u0430\u0439\u0434 \u043f\u0440\u043e \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u044b). \u0412 2009 \u0433\u043e\u0434\u0443 \u0432 \u0441\u0432\u0435\u0442 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u043a\u043d\u0438\u0433\u0430 Elements of programming (Stepanov, McJones) \u0438 \u0433\u0434\u0435 \u043f\u043e-\u043c\u043e\u0435\u043c\u0443 \u043d\u0435\u0442 \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0431\u0435\u0437 \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u043e\u0432. \u0412 2011 \u043d\u043e\u0432\u044b\u0439 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442 \u044f\u0437\u044b\u043a\u0430 \u0441++11, \u0433\u0434\u0435 \u0432 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 (\u043f\u0440\u044f\u043c \u043e\u0447\u0435\u043d\u044c \u0436\u0430\u043b\u044c) \u0444\u0438\u0447\u0430\u0445 \u0444\u0438\u0433\u0443\u0440\u0438\u0440\u0443\u044e\u0442 \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u044b. \u0412 2014 \u043c\u0438\u0440 \u0432\u0438\u0434\u0438\u0442 \u0442\u0432\u043e\u0440\u0435\u043d\u044c\u0435 \u0421\u0442\u0440\u0430\u0443\u0441\u0442\u0440\u0443\u043f\u0430 &#8212; Tour of C++, \u0433\u0434\u0435 \u0433\u043b\u0430\u0432\u0430 5.4 \u043d\u0430\u0437\u0432\u0430\u043d\u0430 Concepts and Generic Programming, \u0445\u043e\u0442\u044f \u044f\u0437\u044b\u043a \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043a\u0435\u0439\u0432\u043e\u0440\u0434 concept. \u0413\u043e\u0434\u043e\u043c \u0440\u0430\u043d\u0435\u0435, \u0432 2013, \u0410\u043d\u0434\u0440\u044e \u0421\u0430\u0442\u0442\u043e\u043d \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 \u0431\u0443\u043c\u0430\u0433\u0443 Concepts Lite. \u0412 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0435 \u0441++14 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u0430\u044f \u0444\u0438\u0447\u0430 digit separators, \u043d\u043e \u043d\u0435\u0442 \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u043e\u0432. \u0412 2017 \u043d\u0430 \u0440\u0435\u0434\u0434\u0438\u0442\u0435 \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u044e\u0442 c++17 \u0438 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e\u0442 \u043e\u0442\u0434\u043e\u0445\u043d\u0443\u0442\u044c \u0435\u0449\u0435 \u0442\u0440\u0438 \u0433\u043e\u0434\u0430.<\/p>\n<p>\u0427\u0435\u0440\u0435\u0437 \u0442\u0440\u0438 \u0433\u043e\u0434\u0430 \u0441\u043e\u0447\u0443\u0432\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 html \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0437\u0430\u0445\u043e\u0447\u0435\u0442 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u044f\u0437\u044b\u043a \u0441 \u0447\u0438\u0441\u0442\u043e\u0433\u043e \u043b\u0438\u0441\u0442\u0430, \u0437\u0430\u044e\u0437\u0430\u0432 \u0438 \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u044b, \u0438 \u043c\u043e\u0434\u0443\u043b\u0438. \u041c\u043e\u0434\u0443\u043b\u0438 \u043f\u0440\u0438\u0432\u043d\u043e\u0441\u044f\u0442 \u0432\u0430\u0436\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e &#8212; \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u0418\u0434\u0435\u044f \u0432 \u0448\u0430\u0433 \u0437\u0430 \u0448\u0430\u0433\u043e\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0438 \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0438\u0445 \u043f\u043e\u0441\u043b\u0435 \u0432 \u043d\u0435\u0447\u0442\u043e \u043e\u0441\u043e\u0437\u043d\u0430\u043d\u043e\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043b\u0438\u043d\u0442\u0435\u0440.<\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e print:<\/p>\n<pre><code class=\"cmake\">\/\/ guard for non-printable types template&lt;typename T, typename... Ts> void print(const T&amp; x, const Ts&amp;...) {   auto msg = \"\\n[error] not supported print operation for type \";   std::cout &lt;&lt; msg &lt;&lt; typeid(x).name() &lt;&lt; \"\\n\"; }  \/\/ print first arg and continue with rest template&lt;Printable T, typename... Ts> void print(const T&amp; x, const Ts&amp;... rest) { ... }<\/code><\/pre>\n<p>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0434\u043b\u044f \u043c\u0430\u0442\u0447\u0438\u043d\u0433\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043b\u0438\u043d\u0442\u0435\u0440\u0430 (javascript \u043a\u043e\u0434\u0430) \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442\u044c \u043a\u0430\u043a-\u0442\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cmake\">\/\/ checking for pair of quotes, while skipping whats inside them template&lt;InputIterator I> constexpr result_t lint(...) {     auto pred = [](char ch){ return ch == '\\'' || ch == '\"'; };     ... }<\/code><\/pre>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0432\u044b\u0448\u0435 constexpr, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u0435\u0441\u0442\u044b \u043d\u0430 \u043a\u0430\u0436\u0434\u0443\u044e! \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044e \u043c\u043e\u0434\u0443\u043b\u044f:<\/p>\n<pre><code class=\"cmake\">constexpr auto test(const std::string_view str) {    auto p = std::make_pair(std::begin(str), std::end(str));    return !lint(..., p) &amp;&amp; p.first == p.second; }  static_assert(test(\"'foo'\"), \"single quoted string test\"); static_assert(test(\"'\\\\' quoted'\"), \"string with escaped single quote test\");<\/code><\/pre>\n<p>\u0423 \u043b\u0438\u043d\u0442\u0435\u0440\u0430, \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0432\u044b\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441:<\/p>\n<pre><code class=\"cmake\">result_t lint(..., \/* pairs of iterators *\/) { }<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0438\u0434\u0435\u044f \u0432\u043f\u043e\u043b\u043d\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0430\u044f: \u043c\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c. \u041c\u043e\u0436\u0435\u043c \u0440\u0435\u0448\u0438\u0442\u044c \u0435\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f, \u0430 \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0438\u0434\u0435\u044e \u0438\u0437 \u0432\u0438\u0434\u0435\u043e Better Code: Runtime Polymorphism (Sean Parent) &#8212; \u0432 \u0434\u0432\u0443\u0445 \u0441\u043b\u043e\u0432\u0430\u0445, \u0442\u043e\u0442 \u0436\u0435 \u0441\u0430\u043c\u044b\u0439 \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c, \u043d\u043e \u0443\u0434\u043e\u0431\u043d\u0435\u0435 (e.g. extension of built-in types). \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c:<\/p>\n<pre><code class=\"cmake\">struct keyword_t { std::size_t id; }; template&lt;InputIterator I> constexpr result_t lint(const keyword_t&amp; x, matcher&lt;I>&amp; m) { ... }  \/\/ models forall relation \/\/ if at least one fails -> all fail template &lt;InputIterator I> constexpr result_t lint(const std::vector&lt;linter>&amp; xs, matcher&lt;I>&amp; m) { ... }<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0442\u0438\u043f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u0432\u0442\u043e\u0440\u043e\u0439 &#8212; \u043e\u0431\u0435\u0440\u0442\u043a\u0430 \u043d\u0430\u0434 \u043f\u0430\u0440\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432. \u041e\u0431\u0435\u0440\u0442\u043a\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"cmake\">template &lt;InputIterator I>  struct matcher {     I first;      I last;     constexpr matcher(I first, I last) : first{first}, last{last} {}      \/\/ advance 'first' while predicate is hold     template &lt;Predicate&lt;value_t> Op>     constexpr void skip(Op pred) {         first = std::find_if_not(first, last, std::move(pred));     }     ...<\/code><\/pre>\n<p>\u0415\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u0442\u0438\u043f\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f result_t. \u0423 \u043b\u0438\u043d\u0442\u0435\u0440\u0430 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0438, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f: \u0438\u043b\u0438 \u043c\u044b \u043d\u0430\u0448\u043b\u0438 \u043d\u0435\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435, \u0438\u043b\u0438 \u0432\u0441\u0435 \u043e\u043a. \u041f\u043e \u0438\u0434\u0435\u0435, \u0432\u044b\u0431\u043e\u0440 \u043f\u0430\u0434\u0430\u0435\u0442 \u043d\u0430 bool, \u043d\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0435\u043d \u043b\u0438\u043d\u0442\u0435\u0440 \u0447\u0443\u0442\u044c-\u0447\u0443\u0442\u044c \u043f\u043e\u0443\u043c\u043d\u0435\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 std::optional\\&lt;std::size_t\\>. \u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u043e\u043a, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043f\u0443\u0441\u0442\u043e\u0439 \u043e\u043f\u0448\u0438\u043e\u043d\u0430\u043b, \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 &#8212; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u043d\u043d\u044b\u0445 \u0448\u0430\u0433\u043e\u0432 \u0434\u043e \u043d\u0435\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043b\u0438\u043d\u0442\u0435\u0440 \u043d\u0430\u0448\u0435\u043b \u043d\u0435\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d \u0438\u043b\u0438 \u043d\u0435 \u043d\u0430\u0448\u0435\u043b \u0438\u0441\u043a\u043e\u043c\u044b\u0439, \u043a\u0438\u0434\u0430\u0435\u043c \u044d\u043a\u0441\u0435\u043f\u0448\u043d:<\/p>\n<pre><code class=\"cmake\">struct panic_t { }; template &lt;InputIterator I> constexpr result_t lint(const panic_t&amp;, matcher&lt;I>&amp; m) {     return 0         ? result_t{}         : throw std::domain_error(\"\\n err near \\n-> \" + m.debug_info()); }  struct iff_t { linter a; linter b; }; \/\/ models relation between pair of linters \/\/ if linter 'a' not fails, linter 'b' must not fail template &lt;InputIterator I> constexpr result_t lint(const iff_t&amp; x, matcher&lt;I>&amp; m) {     auto lhs = lint(x.a, m);     if (lhs.has_value()) return lhs;     auto rhs = lint(x.b, m);     return rhs.has_value() ? lint(panic_t{}, m) : result_t{}; }<\/code><\/pre>\n<p>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043d\u0430\u0448\u0435\u0433\u043e \u043b\u0438\u043d\u0442\u0435\u0440\u0430 \u0437\u0430\u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c (\u0438\u043b\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u043e\u0432\u0430\u0442\u044c), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0430\u0440\u0443\/\u0442\u0440\u043e\u0439\u043a\u0443 \u0441\u0432\u044f\u0437\u0443\u044e\u0449\u0438\u0445:<\/p>\n<pre><code class=\"cmake\">struct or_t { linter a; linter b; }; template &lt;InputIterator I> constexpr result_t lint(const or_t&amp; x, matcher&lt;I>&amp; m) {     return lint(x.a, m) ? lint(x.b, m) : result_t{}; }  struct optional_t { linter a; }; template &lt;InputIterator I> constexpr result_t lint(const optional_t&amp; x, matcher&lt;I>&amp; m) {     lint(x.a, m);     return {}; }  \/\/ models forall relation \/\/ if at least one fails -> all fail template &lt;InputIterator I> constexpr result_t lint(const std::vector&lt;linter>&amp; xs, matcher&lt;I>&amp; m) {     for (const auto&amp; x : xs) {         auto r = lint(x, m);         if (r.has_value()) return r;     }     return {}; }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a \u0440\u0430\u0437\u0431\u043e\u0440\u043a\u0435 (&#171;\u043b\u0438\u043d\u0442\u0438\u043d\u0433\u0443&#187;) javascript \u043a\u043e\u0434\u0430. \u0425\u0435\u0434\u0435\u0440\u044b (\u0438\u043b\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u044b) javascript \u0444\u0430\u0439\u043b\u043e\u0432 \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"typescript\">import * as foo from \"..\/foo\" import bar, { boo, kung as fu, mu } from \"..\/bar\";<\/code><\/pre>\n<p>\u0413\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0430 \u0445\u0435\u0434\u0435\u0440\u043e\u0432 \u0442\u0443\u0442: <a href=\"https:\/\/262.ecma-international.org\/6.0\/#sec-imports\" rel=\"noopener noreferrer nofollow\">https:\/\/262.ecma-international.org\/6.0\/#sec-imports<\/a> .<br \/> \u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0434\u043b\u044f \u0445\u0435\u0434\u0435\u0440\u043e\u0432 import_t \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u0432\u0441\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0448\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b:<\/p>\n<pre><code class=\"cmake\">struct import_t{}; template&lt;InputIterator I> result_t lint(const import_t&amp;, matcher&lt;I>&amp; m) { ... }<\/code><\/pre>\n<p>\u0412\u043d\u0443\u0442\u0440\u0438 \u0445\u043e\u0442\u044f \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 (\u0442\u0443\u0442 \u043f\u0440\u044f\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c, \u0447\u0442\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0435 \u0431\u0435\u0437 \u0432\u0441\u044f\u043a\u0438\u0445 while \u0438 for-loop \ud83d\ude42<\/p>\n<pre><code class=\"cmake\">\/\/ match: * as foo auto namespace_import = iff_t{     char_t{context::Chars::Star},     std::vector&lt;linter>{         keyword_t{context::Keywords::As},         identifier_t{}     } };  \/\/ match: { foo, bar as boo, ... } auto named_import = iff_t{     char_t{context::Chars::LeftCurlyBracket},     std::vector&lt;linter>{         optional_t{import_var_list_t{}},         char_t{context::Chars::RightCurlyBracket},     } };  \/\/ match: foo | foo, * as bar | foo, { bar... } auto imported_default_binding = std::vector&lt;linter>{     identifier_t{},     optional_t {         iff_t {             char_t{context::Chars::Comma},             or_t{                 namespace_import,                 named_import             }         }     } };  \/\/ and combining all togather  auto rule = iff_t{     keyword_t{ context::Keywords::Import },     or_t{         std::vector&lt;linter>{             string_t{},             optional_t{char_t{context::Chars::Semicolon}},         },         std::vector&lt;linter>{             or3_t {                 namespace_import,                 named_import,                 imported_default_binding,             },             keyword_t{context::Keywords::From},             string_t{},             optional_t{char_t{context::Chars::Semicolon}},         }     } };<\/code><\/pre>\n<p>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 import_t \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u0443\u0435\u0442 \u0433\u0440\u0430\u0444. \u0415\u0441\u043b\u0438 \u0432 \u0433\u0440\u0430\u0444\u0430\u0445 \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0438 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u0442\u0441\u044f \u0446\u0438\u043a\u043b, \u0443\u043d\u043e\u0441\u0438\u043c \u0435\u0433\u043e \u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0434\u043e\u0431\u0438\u0432\u0430\u0435\u043c\u0441\u044f direct acyclic graph. \u041f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0446\u0438\u043a\u043b\u0430 \u0435\u0441\u0442\u044c \u0442\u043e\u043a\u0435\u043d import_var_list_t \u0432\u044b\u0448\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u0430\u0442\u0447\u0438\u0442 { foo, bar, &#8230;}, \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0442\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0442\u043e\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044e.<\/p>\n<p>\u041a\u0430\u043a-\u0442\u043e \u043d\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u0438\u0441\u0430\u0442\u044c, \u0442\u0430\u043a \u043a\u0430\u043a \u043b\u0438\u043d\u0442\u0435\u0440 \u0435\u0449\u0435 \u043e\u0439 \u043a\u0430\u043a \u0434\u0430\u043b\u0435\u043a \u043e\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f. \u0425\u043e\u0447\u0435\u0442\u0441\u044f \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u043a\u043d\u0438\u0433\u0443 JavaScript: The Good Parts (Douglas Crockford, 8 May 2008), \u043a\u043e\u0442\u043e\u0440\u0430\u044f, \u043a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f, \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u044e\u0437\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e &#171;\u0445\u043e\u0440\u043e\u0448\u0438\u0439&#187; \u0441\u0430\u0431\u0441\u0435\u0442 \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0438 \u0438\u0437 &#171;\u044f\u0432\u0430\u0441\u043a\u0440\u0438\u043f\u0442\u0430&#187;. \u041d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u0441\u0430\u0431\u0441\u0435\u0442 \u0431\u0443\u0434\u0435\u0442 \u0435\u0449\u0435 \u043c\u0435\u043d\u044c\u0448\u0435 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, for-loop, while &#8212; \u043d\u0435\u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u044b; var, let \u0437\u0430\u043f\u0440\u0435\u0449\u0435\u043d\u043d\u044b), \u0442\u043e \u0435\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e \u0438 \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u043b\u0438\u043d\u0442\u0435\u0440\u0430 \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043d\u0435 \u0442\u0430\u043a\u0430\u044f \u0443\u0436 \u043d\u0435\u043f\u043e\u0441\u0438\u043b\u044c\u043d\u0430\u044f.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/673388\/\"> https:\/\/habr.com\/ru\/post\/673388\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-334986","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/334986","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=334986"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/334986\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=334986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=334986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=334986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}