Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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 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:)

like image 854
Dinaiz Avatar asked Jun 26 '10 22:06

Dinaiz


2 Answers

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.

like image 131
stinky472 Avatar answered Sep 18 '22 12:09

stinky472


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.

like image 45
Edward Strange Avatar answered Sep 21 '22 12:09

Edward Strange