实例介绍
This book isn’t meant to teach the C++ programming language. It’s about functional programming and how it fits in with C++. Functional programming provides a differ- ent way to think about software design and a different way of programming, compared to the imperative, object-oriented styles common
Functional Programming in C++ Functional programming inm ctt IVAN CUKIC MANNING SHELTER ISLAND ForonlineinformationandorderingofthisandotherManningbookspleasevisitwww.manning.com The publisher offers discounts on this book when ordered in quantity For more information, please contact Special sales department Manning publications co 20 Baldwin road PO Box 761 Shelter island. ny11964 Emailorders@manning.com C2019 by Manning Publications Co. All rights reserved no part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps oo Recognizing the importance of preserving what has been written, it is Manning,'s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine Manning Publications Co Development editor: Marina michaels 20 Baldwin Road Technical development editor: Mark Elston PO Box 761 Review editor: Aleksandar dragosavljevic Shelter island. nY11964 Project editor: Lori Weider Copy editor: Sharon Wilkey Proofreader: Tiffany taylor Technical proofreader: Yongwei wu Typesetter: Happenstance Type-O-Rama Cover designer: Leslie haimes ISBN9781617293818 Printed in the United states of america 12345678910-SP-232221201918 brief contents 1 Introduction to functional programming 2 Getting started with functional programming 21 3■ Function obiects45 4 Creating new functions from the old ones 71 5 Purity: Avoiding mutable state 100 6■ Lazy evaluation122 7 Ranges 142 8 Functional data structures 158 9 Algebraic data types and pattern matching 174 10■ Monads199 11 Template metaprogramming 226 12 Functional design for concurrent systems 248 13 Testing and debugging 274 contents presa acknowledgments xu about this book xvii about the author xxi Introduction to functional programming I 1.1 What is functional programming? 2 Relationship with object-oriented programming 3.A concrete example of imperative us. declarative programming 3 1.2 Pure functions 8 1. 2. 1 Avoiding mutable state 10 1.3 Thinking functionally 12 1.4 Benefits of functional programming 14 Code brevity and readability 15. Concurrency and synchronization 16. Continuous optimization 17 1.5 Evolution of C++ as a functional programming g language 17 1.6 What you'll learn in this book 19 CONTENTS Getting started with functional programming 21 2.1 Functions taking functions? 22 2.2 Examples from the stl 24 Calculating averages 24 Folding 27- String trimming 31 Partitioning collections based on a predicate 32 Filtering and transforming 34 2.3 Composability problems of STL algorithms 36 2.4 Writing your own higher-order functions 38 Receiving functions as arguments 38. Implementing with loops 38 Recursion and tail-call optimization 40. Implementing using folds 43 Function objects 45 3.1 Functions and function objects 46 Automatic return type deduction 46- Function pointers49· Call operator overloading50· Creating generic function objects 52 3.2 Lambdas and closures 54 Lambda syntax 55. Under the hood of lambdas 56 Creating arbitrary member variables in lambdas 59 Generic lambdas 60 3.3 Writing function objects that are even terser than lambdas 61 Operator function objects in sTL 64 Operator function object in other libraries 65 8.4 Wrapping function objects with std: function 68 4 Creating new functions from the old ones 7I 4.1 Partial function application 72 A generic way to convert binary functions into unary ones 74. Using std: bind to bind values to specific function arguments 77 Reversing the arguments of a binary function 79. Using std: bind on functions with more arguments 80 Using lambdas as an alternative for std:: bind 83 4.2 Currying: a different way to look at functions 85 Creating curried functions the easier way 87 Using currying with database access 88 Currying and partial function application 【实例截图】
【核心代码】
标签:
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论