Can Asio be used without boost or C++11?

2019-08-10 16:43发布

问题:

I'm looking at libraries to help build a scalable tcp/ip server, and Boost::ASIO looks pretty nice to make async socket i/o work homogeneously across platforms (We need to support at least OSX, Linux x86, and Windows, probably Solaris, maybe HP-UX & AIX).

Management is dead-set against using Boost in our product, mostly due to it being 'bloated', and due to issues we've had in the past with conflicts, as our code gets statically linked with customer code (which may also be using boost, possibly not the same version).

The Asio page claims that it can be used without boost, although it's pretty vague, as later it also says "When using C++11 ... Asio can be used independently of Boost ...", which seems to imply it won't work on a C++03 compiler. I was thinking I could simply do a '#define asio proprietary_asio' before including the header to avoid the symbol clash issue.

I just tested VS2013 on my local machine, and it compiled; Does anyone know which particular C++11 features are needed? I need to (at the very least) support VS2012/2013 on windows, gcc 4.4 (maybe 4.3) on linux, and XCode 5.1 on OSX.

I'm guessing the problem is going to be with the old version of GCC...

回答1:

I've used ASIO with MS VC++ 2013, without using any other parts of Boost.

Most ASIO code uses boost::bind, but VC++ 2013 includes a std::bind that works fine for the job. A fair amount of Boost demo code also uses boost::array, but this is just a fairly ordinary array--you can use std::array, or std::vector, or any number of other possibilities.

Warning: while this has worked fine for me in what I've done, I'm pretty certain I haven't used all parts of ASIO, and I'm ever more certain I haven't combined them in every possible way. As such, I can say it has worked, and I don't recall any issues that seemed to be related to lack of using other parts of Boost, but at the time time, it's always possible that (depending what you use and how) you could run into an issue I simply never encountered (e.g., something that works with boost::bind that just doesn't work (at least the same way) with VC++ 2013's implementation of std::bind.

The other compilers are a lot less certain--with a newer version of gcc, there would be no problem, but 4.4 or 4.3 is pretty darned old. It's been long enough since I did anything on OS X that I'm uncertain what compiler goes with XCode 5.1.



回答2:

Asio might be using placeholder or smart pointers or even bind() function which were parts of boost and were included in C++11 std library. Without those, you can't use asio.



回答3:

https://github.com/chriskohlhoff/asio/tree/master/asio/src/examples

It appears that Asio's examples are filled with both C++03, C++11, and C++14 version. In this vein, Asio should work with C++03