简体   繁体   English

C ++:你是否正在使用Loki或Boost进行仿函数?

[英]C++: Are YOU using Loki or Boost for functors ?

I've been reading Alexandrescu's book, Modern C++ design , and I've been quite impressed by the techniques he uses, so I wanted to add Loki library to my application. 我一直在阅读Alexandrescu的书,现代C ++设计,我对他使用的技术印象深刻,所以我想在我的应用程序中添加Loki库

However, after further investigation, I saw that boost, that I'm already using, provides a lot of similar functionality (not all though, I couldn't find a singleton in boost for example) 然而,经过进一步的调查,我看到我已经在使用的提升提供了很多类似的功能(不是全部,但是,例如,我无法在boost中找到单例)

I was mostly interested in using loki because of the policy based design and the functors. 由于基于策略的设计和仿函数,我最感兴趣的是使用loki。

To me both, boost and loki have pros and cons. 对我而言,boost和loki都有利有弊。 The main concern I have with loki is the poor documentation (the library isn't tied to the book anymore) but it seems to me that loki is more powerful and flexible than boost in some areas (I might be wrong on that one) 我对loki的主要关注是糟糕的文档(图书馆不再与书籍联系在一起了)但在我看来,loki比某些领域的提升更强大,更灵活(我可能错了)

Before choosing to use boost or loki for functors and policies, I'd like to know the opinion of people who use them in real life. 在选择使用boost或loki作为仿函数和策略之前,我想知道在现实生活中使用它们的人的意见。

Sometimes things look very good on paper but have some drawbacks when you use them for real:) 有时在纸上看起来非常好但是当你真正使用它们时会有一些缺点:)

Alexandrescu had very interesting ideas (type lists, policy-based class templates, etc) but a lot of them have been improved upon in boost along with being tested across a wider range of compilers for portability and correctness. Alexandrescu有非常有趣的想法(类型列表,基于策略的类模板等),但其中很多已经在boost中进行了改进,并且在更广泛的编译器中进行了测试,以实现可移植性和正确性。

I'd recommend preferring boost whenever possible merely for these reasons. 我建议只要出于这些原因,尽可能选择增强。 That said, Modern C++ Design still provides a lot of insight into the flexibility of C++ and a look into one person's mind (a very good one) to approach a lot of common programming problems. 也就是说,现代C ++设计仍然提供了很多关于C ++灵活性的见解,并且可以深入了解一个人的思想(非常好的)来解决许多常见的编程问题。

For instance, policy-based smart pointers are a very neat idea, but we can find why the boost authors chose not to implement shared_ptr and scoped_ptr this way: 例如,基于策略的智能指针是一个非常巧妙的想法,但我们可以找到为什么boost作者选择不以这种方式实现shared_ptr和scoped_ptr:

A. Parameterization discourages users. A.参数化不鼓励用户。 The shared_ptr template is carefully crafted to meet common needs without extensive parameterization. shared_ptr模板经过精心设计,无需大量参数化即可满足常见需求。 Some day a highly configurable smart pointer may be invented that is also very easy to use and very hard to misuse. 有一天,可能会发明一种高度可配置的智能指针,它也非常容易使用并且很难被滥用。 Until then, shared_ptr is the smart pointer of choice for a wide range of applications. 在此之前,shared_ptr是各种应用程序的首选智能指针。 (Those interested in policy based smart pointers should read Modern C++ Design by Andrei Alexandrescu.) (那些对基于策略的智能指针感兴趣的人应该阅读Andrei Alexandrescu的Modern C ++ Design。)

If you do need a wide variety of smart pointers and you and your team are comfortable working extensively with template parameterization, then a policy-based approach to implementing smart pointers might work for you. 如果您确实需要各种各样的智能指针,并且您和您的团队很乐意在模板参数化方面进行广泛的工作,那么实现智能指针的基于策略的方法可能对您有用。 However, scoped_ptr and shared_ptr (along with weak_ptr) tend to do the job quite thoroughly. 但是,scoped_ptr和shared_ptr(以及weak_ptr)倾向于完全完成这项工作。 The combinatorial behavior of policy classes is probably better used for something for which there are a wide variety of useful combinations. 策略类的组合行为可能更适用于存在各种有用组合的事物。

Nevertheless, there are still some interesting proposals from Alexandrescu that boost has not addressed. 尽管如此,Alexandrescu仍然提出一些有趣的建议,即提升尚未解决。 MOJO , for instance, is still genuinely useful until compilers do a better job implementing move constructors or until we can use rvalue references from C++0x. 例如,在编译器更好地实现移动构造函数或者直到我们可以使用来自C ++ 0x的右值引用之前, MOJO仍然真正有用。 He also has some very interesting thoughts on implementing memory allocators. 他还对实现内存分配器有一些非常有趣的想法。

As for the question, we use parts of Loki needed for mojo in our commercial project, but mostly boost when it's appropriate. 至于这个问题,我们在我们的商业项目中使用了mojo所需的部分,但是在适当的时候大多提升。

One thing to maybe consider is that boost libraries have to go through a peer review process during acceptance. 可以考虑的一件事是,升级库必须在验收期间通过同行评审过程。 After that of course I believe there's really very little oversight into what changes go in, but at least there's some review before they're accepted. 在那之后,我当然相信对变化的影响确实很少,但至少在接受之前会有一些评论。 Loki is just one man's vision. Loki只是一个人的愿景。 Of course Alexandrescu is quite good, but still...it's all his ideas and there's no further review than that. 当然亚历山大里斯库是相当不错的,但仍然......这都是他的想法,并没有比那更进一步的评论。

I'm using Boost in my whole C++ environnement like an extension to the Standard Library (with VC9 and VC10). 我在整个C ++环境中使用Boost,就像标准库的扩展(使用VC9和VC10)。

I don't use it on all projects. 我不会在所有项目中使用它。

I use it on personal projects (mostly games) where I got full control of what are the dependencies. 我在个人项目(主要是游戏)中使用它,在那里我完全控制了什么是依赖项。

I'm using boost::function in a big game project (with several other libraries from boost). 我在一个大型游戏项目中使用boost :: function(还有一些来自boost的其他库)。

Loki is good too but I didn't feel the need. Loki也很好,但我觉得不需要。 I think the only part of the library I'm thinking of using is the Singleton but I'm using a custom one that is fine enough for the moment. 我认为我正在考虑使用的库的唯一部分是Singleton,但我正在使用一个当前足够好的自定义库。

C ++ 0x是我用于快速函数对象的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM