C++0x (C++11) as functional language?

后端 未结 2 487
Happy的楠姐
Happy的楠姐 2021-02-05 09:11

i\'m wondering if C++0x (C++11) (with lambdas and perfect forwarding) is (a superset of) a functional language. is there any feature of functional languages, that C++ doesn\'t h

2条回答
  •  没有蜡笔的小新
    2021-02-05 09:58

    Check out the list of Functional Programming Languages definitions and discussion on the C2 wiki.

    Some of the most common (and least disputed features) are:

    • First class functions - function class represents first class functions.
    • Higher Order Functions - Can be emulated with function objects.
    • Lexical Closures - Can be emulated with classes.
    • Single Assignment - More of a convention. You can do this by declaring all variables const.
    • Lazy Evaluation - Can be achieved with TMP
    • Garbage Collection - still missing. Pretty much necessary in a functional language, since lifetime and scope are not the same, as @Pascal pointed out in the comments above.
    • Type Inference - auto
    • Tail Call Optimization - Not strictly necessary for a functional language, but compiler dependent in C++.

提交回复
热议问题