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.
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)
I was mostly interested in using loki because of the policy based design and the functors.
To me both, boost and loki have pros and cons. 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 开发者_JS百科and flexible than boost in some areas (I might be wrong on that one)
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.
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.
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.
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:
A. Parameterization discourages users. The shared_ptr template is carefully crafted to meet common needs without extensive parameterization. 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. (Those interested in policy based smart pointers should read Modern C++ Design by Andrei Alexandrescu.)
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. 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. 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. 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.
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. 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).
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).
Loki is good too but I didn't feel the need. 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.
C++0x is what I'm using for quick function objects.
精彩评论