Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is boost asio and c++11 a good match?

A client of mine wants me to make a high performance, reliable server which receives datastreams via sockets. He expects it to be in c++

It's been a while that i was doing c++ fulltime so I've been reading up a bit. Asio seems to be a good bet for networking in c++, and c++11 seems like a great new version of c++ with a lot of new features.

My question: is it possible to use both reliably? Does it make sense? Should I avoid certain c++11 features like lambdas?

like image 990
Toad Avatar asked Sep 08 '12 12:09

Toad


People also ask

Is boost ASIO cross platform?

Boost. Asio is a cross-platform C++ library for network and low-level I/O programming that provides developers with a consistent asynchronous model using a modern C++ approach.

How does boost ASIO work?

At its core, Boost Asio provides a task execution framework that you can use to perform operations of any kind. You create your tasks as function objects and post them to a task queue maintained by Boost Asio. You enlist one or more threads to pick these tasks (function objects) and invoke them.


2 Answers

I'd base "C++11 features to avoid" primarily on your planned target compiler(s). I don't see any reason to avoid lambdas -- all the major compilers already support them, and the they provide a substantial improvement in readability.

On the other hand, depending on the compiler(s) you care about, you might want/need to avoid things like variadic templates and/or braced initializer lists.

like image 63
Jerry Coffin Avatar answered Nov 07 '22 09:11

Jerry Coffin


You can use the two of them together with no issues. For things implemented in both Boost and the C++11 STL, it's your choice which to use. In most cases, it makes very little difference. If you use Boost, you'll be portable to C++03 platforms as well (at least, that part of your code will be if it doesn't use C++11 features directly).

Boost was carefully designed to be able to take advantage of C++11 features where they are available without having to provide a "dumbed down" interface or poor performance to support where they're not.

And if you need good asynchronous I/O, you need some library to provide it. Boost is pretty hard to beat, whether you're using C++11 or not.

If your question is "Is there some specific reason I wouldn't want to use Boost with C++11 or C++11 with Boost", the answer is no. If you need some feature Boost provides, like asio, and only need to support C++11 platforms, then they're a perfect match for your application.

like image 21
David Schwartz Avatar answered Nov 07 '22 09:11

David Schwartz