久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <small id='W60wO'></small><noframes id='W60wO'>

        <bdo id='W60wO'></bdo><ul id='W60wO'></ul>
      <i id='W60wO'><tr id='W60wO'><dt id='W60wO'><q id='W60wO'><span id='W60wO'><b id='W60wO'><form id='W60wO'><ins id='W60wO'></ins><ul id='W60wO'></ul><sub id='W60wO'></sub></form><legend id='W60wO'></legend><bdo id='W60wO'><pre id='W60wO'><center id='W60wO'></center></pre></bdo></b><th id='W60wO'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='W60wO'><tfoot id='W60wO'></tfoot><dl id='W60wO'><fieldset id='W60wO'></fieldset></dl></div>
      <tfoot id='W60wO'></tfoot>
      1. <legend id='W60wO'><style id='W60wO'><dir id='W60wO'><q id='W60wO'></q></dir></style></legend>
      2. 通過泛型 lambda 理解 Y Combinator

        Understanding Y Combinator through generic lambdas(通過泛型 lambda 理解 Y Combinator)
        <tfoot id='zzNBU'></tfoot>

        1. <small id='zzNBU'></small><noframes id='zzNBU'>

              <tbody id='zzNBU'></tbody>
              <bdo id='zzNBU'></bdo><ul id='zzNBU'></ul>
              • <legend id='zzNBU'><style id='zzNBU'><dir id='zzNBU'><q id='zzNBU'></q></dir></style></legend>

                <i id='zzNBU'><tr id='zzNBU'><dt id='zzNBU'><q id='zzNBU'><span id='zzNBU'><b id='zzNBU'><form id='zzNBU'><ins id='zzNBU'></ins><ul id='zzNBU'></ul><sub id='zzNBU'></sub></form><legend id='zzNBU'></legend><bdo id='zzNBU'><pre id='zzNBU'><center id='zzNBU'></center></pre></bdo></b><th id='zzNBU'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='zzNBU'><tfoot id='zzNBU'></tfoot><dl id='zzNBU'><fieldset id='zzNBU'></fieldset></dl></div>
                1. 本文介紹了通過泛型 lambda 理解 Y Combinator的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  在構建一個基于 lambda 的小型元編程庫時,我有必要在 C++14 通用 lambda 中使用遞歸來實現一個 左折疊.

                  While building a small lambda-based metaprogramming library, I had the necessity of using recursion in a C++14 generic lambda, to implement a left-fold.

                  我自己的解決方案是將 lambda 本身作為其參數之一傳遞,如下所示:

                  My own solution was passing the lambda itself as one of its parameters, like this:

                  template <typename TAcc, typename TF, typename... Ts>
                  constexpr auto fold_l_impl(TAcc acc, TF f, Ts... xs)
                  {
                      // Folding step.
                      auto step([=](auto self)
                      {
                          return [=](auto y_acc, auto y_x, auto... y_xs)
                          {
                              // Compute next folding step.
                              auto next(f(y_acc, y_x));
                  
                              // Recurse if required.
                              return static_if(not_empty(y_xs...))
                                  .then([=]
                                      {
                                          // Recursive case.
                                          return self(self)(next, y_xs...);
                                      })
                                  .else_([=]
                                      {
                                          // Base case.
                                          return next;
                                      })();
                          };
                      });
                  
                      // Start the left-fold.
                      return step(step)(acc, xs...);
                  }
                  

                  step 是開始遞歸的主要"lambda.它返回一個具有所需左折疊簽名的函數(累加器,當前項目,剩余項目...).

                  step is the "main" lambda that starts off the recursion. It returns a function with the desired left-fold signature (accumulator, current item, remaining items...).

                  該函數使用self(self)(next, y_xs...)遞歸調用自身.

                  The function calls itself recursively by using self(self)(next, y_xs...).

                  我最近遇到了這個提議想在標準庫中加入一個Y Combinator,看了之后,和我在這里做的事情非常相似.

                  I've recently come across this proposal that wants to add a Y Combinator to the Standard Library, and after reading it, it seems extremely similar to what I am doing here.

                  不幸的是,Y Combinator 的概念對我來說仍然沒有點擊"——我遺漏了一些東西,我無法想象如何概括我對任何函數的 self 參數所做的事情,避免 step 樣板.

                  Unfortunately, the concept of the Y Combinator still doesn't "click" for me - I am missing something and I cannot visualize how to generalize what I did with the self parameter for any function, avoiding the step boilerplate.

                  我已經閱讀了關于此事的這個優秀的 StackOverflow 答案,但它仍然沒有'為我點擊".

                  I've read this excellent StackOverflow answer regarding the matter, but it still didn't "click" for me.

                  (來自那個答案) 遞歸階乘是這樣定義的:

                  (From that answer) a recursive factorial is defined this way:

                  fact =
                    (recurs) =>
                      (x) =>
                        x == 0 ? 1 : x * recurs(x - 1);
                  

                  recurs 參數似乎與我的 self 參數具有相同的作用.我不明白的是如何在不將 recurs 再次傳入自身的情況下調用 recurs.

                  The recurs parameter seems to have the same role as my self parameter. What I do not understand is how recurs is called without passing recurs into itself again.

                  我必須像這樣調用 self:self(self)(params...).

                  I have to call self like this: self(self)(params...).

                  recurs 的調用方式類似于 recurs(params...).

                  recurs, however, is called like recurs(params...).

                  嘗試調用 self(params...) 會導致編譯器錯誤,通知我 self 只需要一個參數 (這是 auto self lambda 參數).

                  Attempting to call self(params...) results in a compiler error informing me that self requires only a single parameter (which is the auto self lambda parameter).

                  我在這里錯過了什么?我怎樣才能重寫我的 fold_l_impl lambda,使其遞歸可以通過使用 Y Combinator 來泛化?

                  What am I missing here? How could I rewrite my fold_l_impl lambda in such a way that its recursion could be generalized through the use of a Y Combinator?

                  推薦答案

                  這里是一個 y 組合,其中 lambda 被傳遞一個不需要傳遞的遞歸:

                  Here is a y combinate where the lambda is passed a recurs that doesn't need to be passed recurs:

                  template<class F>
                  struct y_combinate_t {
                    F f;
                    template<class...Args>
                    decltype(auto) operator()(Args&&...args)const {
                      return f(*this, std::forward<Args>(args)...);
                    }
                  };
                  template<class F>
                  y_combinate_t<std::decay_t<F>> y_combinate( F&& f ) {
                    return {std::forward<F>(f)};
                  };
                  

                  然后你做:

                    return y_combinate(step)(acc, xs...);
                  

                  和改變

                                     return self(self)(next, y_xs...);
                  

                                     return self(next, y_xs...);
                  

                  這里的技巧是我使用了一個非 lambda 函數對象,它可以訪問自己的 this,我將其作為第一個參數傳遞給 f.

                  the trick here is I used a non-lambda function object that has access to its own this, which I pass to f as its first parameter.

                  這篇關于通過泛型 lambda 理解 Y Combinator的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  In what ways do C++ exceptions slow down code when there are no exceptions thown?(當沒有異常時,C++ 異常會以何種方式減慢代碼速度?)
                  Why catch an exception as reference-to-const?(為什么要捕獲異常作為對 const 的引用?)
                  When and how should I use exception handling?(我應該何時以及如何使用異常處理?)
                  Scope of exception object in C++(C++中異常對象的范圍)
                  Catching exceptions from a constructor#39;s initializer list(從構造函數的初始化列表中捕獲異常)
                  Difference between C++03 throw() specifier C++11 noexcept(C++03 throw() 說明符 C++11 noexcept 之間的區別)
                  <tfoot id='6EIqu'></tfoot>
                    <bdo id='6EIqu'></bdo><ul id='6EIqu'></ul>

                        <tbody id='6EIqu'></tbody>

                      <small id='6EIqu'></small><noframes id='6EIqu'>

                        • <legend id='6EIqu'><style id='6EIqu'><dir id='6EIqu'><q id='6EIqu'></q></dir></style></legend>

                            <i id='6EIqu'><tr id='6EIqu'><dt id='6EIqu'><q id='6EIqu'><span id='6EIqu'><b id='6EIqu'><form id='6EIqu'><ins id='6EIqu'></ins><ul id='6EIqu'></ul><sub id='6EIqu'></sub></form><legend id='6EIqu'></legend><bdo id='6EIqu'><pre id='6EIqu'><center id='6EIqu'></center></pre></bdo></b><th id='6EIqu'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='6EIqu'><tfoot id='6EIqu'></tfoot><dl id='6EIqu'><fieldset id='6EIqu'></fieldset></dl></div>

                            主站蜘蛛池模板: 欧美中文字幕在线观看 | 国产精品一区二区不卡 | wwwxxx欧美| 蜜臀久久久 | 日韩国产欧美 | 欧美日韩在线播放 | 国产精品区二区三区日本 | 国产黄色在线观看 | 日韩精品在线看 | 一区二区国产视频 | 欧美精品一区二区三区四区 | 人人干人人看 | 51调教丨国产调教视频 | 久久免费观看视频 | 丁香婷婷六月天 | 欧美日韩国产精品 | 在线观看黄色小视频 | 欧美一级色 | 精品国产一二三区 | 538精品视频 | 日韩欧美在线观看 | 日韩精品极品视频在线观看免费 | 免费网站观看www在线观看 | 成人一区在线观看 | 亚洲影音 | 国产精品久久久久久久久久久久久久 | 99热1 | 成人免费黄色片 | www.成人网 | 热久久免费视频 | 日韩欧美在线视频 | av一区二区三区在线观看 | 日韩av毛片| 日韩免费视频 | 日韩欧美一区二区三区 | 伊人免费视频 | www.日本黄色 | 国产精品亚洲综合 | 黄色片免费看 | 日韩成人影院 | 亚洲国产成人精品女人久久久 |