Should I use lambdas C ++ 11 now?

Here's my dilemma: I really like lambda and use Boost.Fusion and Phoenix a lot. They are quite mature and play well in many compilers.

What about c ++ 11 lambdas? They are really nice and much easier to use than alternatives to boost (no more functors!). The latest ICC and GCC compilers support them. But there are still many ICC 9.x and GCC 4.1 and lower systems, not to mention XL and Sun compilers. Do these compilers provide lambda support?

I tend to think that maybe I should wait to take advantage of C ++ 11 so that older systems do not reject the code. What do you think? Wait until the old compilers disappear or just do it?

+7
source share
4 answers

Do you need to compile your code using a compiler that does not support C ++ 11 lambdas?

If so, then you cannot use them (obviously). Otherwise, there really is no reason to use them.

There were few changes to the specification of lambda expressions in C ++ 11, so now there is little chance of using them. Of course, there will be random compiler errors, but for the most part this is a bit and far from each other.

The only important lambda-related feature that I know of is not supported by the latest versions of several compilers that support lambda expressions is the one that was added last March, which allows unobtrusive lambdas to be implicitly converted to function pointers. Visual C ++ 2010 and Intel C ++ 11.1 do not support this (I do not have a later version of Intel C ++ with which you can test, sorry). However, Visual C ++ 11 does support implicit conversion.

+13
source

Are you targeting multiple compilers? Then no. If you know exactly which compiler you are targeting, and they handle the syntax in the same way, then go and use the new functions!

+5
source

My prospect is that if you are working on library code, you should probably wait. I want to say that if you want to combine the library either for open source distribution or for use in a commercial cross-platform package, you are unlikely to be able to control what compiler support for lambdas will be available and how it will behave. Fortunately, lambda expressions, no matter how good they are, are mostly about syntactic sugar. They do not offer more functionality than traditional functors, they just make it more pleasant and more localized (of course, I can be wrong in this, my knowledge about using lambda is pretty small). But, as a rule, the library should hide the ugliness of implementation. And if you need to make this library suitable for use in compilers that do not support lambda, you still have to offer alternative portable implementations. Thus, if there is no clear benefit to using lambdas in your library (either in efficiency (compilation time or runtime), or in user mode (for example, if you use lambdas to make your library easier or more intuitive or more intuitive) ), this is probably not worth the effort.

However, for custom code, you can more easily manage the target platforms and / or compilers for your software. In this case, if all the compilers you are going to use lambdas .. support, then go nuts!

Now a philosophical moment, there are standards for people to meet them. This includes, of course, people making compilers, but also people who use them. When people start writing good libraries and / or software that requires lambda support, people who want to use them will start complaining to the compiler developers to add support, which in turn will encourage people to use lambda .. and also the ball.

Finally, judging by the amount of noise that this new standard raises and the excitement that was building in anticipation of its release, I think that programmers will rush to make this standard โ€œstandardโ€, and compiler developers will follow suit to stay alive.

+3
source

In your own code, absolutely, go for it. This is actually a great idea.

For work, stackoverflow is not the right place to request. If you do not make decisions at the place of work, and your compiler knows what you are talking about. In this case, I urge you to be awesome.

+1
source

All Articles