`
febird
  • 浏览: 256226 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Recursive Lambda in C++

 
阅读更多

C++ 标准委员会真是太死板了,既然给 C++ 增加了 lambda,就真的按部就班地套用 lambda 的标准定义,也不加个 lambda的自引用机制。找了半天,除了那些学院派的足以把99%的人搞晕的 Fix Point + Y combinator,一个最实用的解决方案就是把 lambda bind 到 std::function<...>.

我那段需要 recursive lambda 的代码:


这是以 DFS 顺序打印 Tree Shape Automata 的代码,为了各种原因(内存,速度,简洁),设计了一个通用的 for_each_move 来遍历指定 state 的每个直接 target。

如果有 recursive lambda,这代码要更简洁高效一点(假定 [[]] 是引用lambda 自身的那个符号):

这是 C++ Committee 故意的!它就是要让大家难受,以昭显他们的 Pure Academic,他们的 Pure Mathematic!
加一个自引用的符号多容易呀!
分享到:
评论
1 楼 satan_1st 2013-07-24  
据说可以用(*this)取得当前的lambda。

相关推荐

    Recursive Methods in Economic Dynamics.Stokey.Lucas

    Recursive Methods in Economic Dynamics.Stokey.Lucas

    Super-Recursive Algorithms_C++_algorithms_

    《Super-Recursive Algorithms》这本书深入探讨了C++编程语言中的超级递归算法,这是一类在计算理论和算法设计中至关重要的技术。超级递归不仅仅是简单的递归调用,它涉及到了更复杂的数学和计算机科学概念,如元...

    Data Structures and Algorithms in C++ 第四版

    Different types of recursionare discussed, and a recursive call is dissected.■ Chapter 6 discusses binary trees, including implementation, traversal, and search.Balanced trees are also included in ...

    COMP1603 Recursion 1.pptx

    Learn recursive methods in C++ programming language.

    Algorithms in C++, Parts 1-4: Fundamentals, Data Structures, Sorting, Searching

    ### Algorithms in C++, Parts 1-4: Fundamentals, Data Structures, Sorting, Searching #### Part One: Fundamentals ##### Chapter One: Introduction 1. **Algorithms**: This chapter introduces the ...

    Theory.of.Recursive.Functions

    Theory.of.Recursive.Functions

    Recursive Mathematics - Volume 1 Recursive Model Theory part2

    In this book, hyperarithmetic theory is developed at length and used to lift classical recursion theory from integers to recursive ordinals (metarecursion). Two further liftings are then made, first ...

    Recursive_recursive_

    在编程语言中,如Python、Java、C++等,都支持递归函数的实现。例如,在Python中,你可以这样定义一个简单的递归函数来计算阶乘: ```python def factorial(n): if n == 0: # 基本情况 return 1 else: # 递归...

    C++数据结构实现之Recursive.zip

    "C++数据结构实现之Recursive.zip"这个压缩包文件显然是关于使用递归方法在C++中实现数据结构的教学资源。 首先,让我们深入了解一下什么是递归。递归是一种编程技术,它通过调用自身来解决问题或执行任务。在数据...

    数据结构-C++之10-recursive.zip

    数据结构 数据结构_C++之10_recursive

    Learning C++ Functional Programming

    A highly practical guide to building functional code in C++ filled with lots of examples and real-world use cases Book Description Functional programming allows developers to divide programs into ...

    c++ knapsack problem recursive solution

    c++ knapsack problem

    Recursive XML Parser in C

    本项目名为“Recursive XML Parser in C”,它是一个用纯ANSI C编写的递归下降XML解析器,旨在提供一个可移植且高效的解决方案。 1. **递归下降解析**: 递归下降解析是基于解析器语法分析的一种方法,通过函数的...

    Guide to Scientific Computing in C++

    1.1.2 Why You Should Write Scientific Programs in C++ . . 1.1.3 Why You Should Not Write Scientific Programs in C++ 1.1.4 Scope of This Book . . . . . . . . . . . . . . . . . . . 1.2 A First C++ ...

    recursive sql.txt

    postgre sql recursive sql. 在postgoresql 中使用recursive的脚本实现循环查询结果

    Problem Solving with C++ (7th edition)

    In this chapter, the focus is on understanding the process of creating a C++ program from start to finish. The key points covered include: - **Introduction to the C++ Compiler**: Explanation of what ...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    The goal of this guide is to manage this complexity by describing in detail the dos and don'ts of writing C++ code. These rules exist to keep the code base manageable while still allowing coders to ...

    Data.Structures.and.Other.Objects.Using.C++.4th.Edition

    Data Structures and Other Objects Using C++ takes a gentle approach to the data structures course in C++. Providing an early, self-contained review of object-oriented programming and C++, this text ...

    C++函数详解

    1. **内置函数(Built-in Functions)**:C++标准库提供了一系列内置函数,如`std::cout`用于输出,`std::cin`用于输入,以及数学函数如`sqrt`(平方根)等。 2. **用户自定义函数(User-defined Functions)**:...

    Recursive Mathematics - Volume 1 Recursive Model Theory

    In this book, hyperarithmetic theory is developed at length and used to lift classical recursion theory from integers to recursive ordinals (metarecursion). Two further liftings are then made, first ...

Global site tag (gtag.js) - Google Analytics