Did Boost::algorithms get subsumed into standard libraries? - c++

Starting in C++11 (I think) a lot of Boost functionality was available in the STL, or in an extension TR1 (again, if memory serves).
I'm struggling to tell specifically which things were and were not included in C++11 and later versions (and in MSVC++ versions).
Specifically this very old question about joining vector<string> has a nice Boost-based answer: https://stackoverflow.com/a/6334153/197229.
I don't want to add boost dependency to my project so - is this functionality now available in standard libraries?

boost::algorithm::join is not part of the C++ standard library. (nor something with equivalent functionality).
More generally, sometimes things are implemented in Boost.Algorithm and then proposed for standardization (Boyer-Moore, for example), and sometimes I implement things that have been added to the standard library in Boost.Algorithm for people who can't/won't use the latest C++ version (any_of, for example).

boost::algorithm::join has not made its way into the standard library as of yet. There is an open paper (N3594) to have it added to the library, but it is sitting in the Library Evolution working group currently.
You'll either need to use one of the other implementations from that Q&A pair or include boost.

Related

Migrating from Boost to the Standard Library for C++11

I am new user of the boost library. I find my self thinking more about adopting boost for a number of reasons. From what I can tell, it seems that the boost library is a sort of skunkworks sandbox where various C++ TR features for upcoming standardization are tried out before being adopted by the C++ committee - think boost::filesystem and boost::regex,
As an example, I was trying out some of the C++11 regex features in visual studio via the #include header - this worked great until I ported to a target power pc platform, which, at the time used CodeSourcery's GCC 4.7.3. Unfortunately, I realized that at run-time, that much of the regex implementation was incomplete or empty (even thought it compiled) - With a bit of homework, I should have realized this beforehand, however now that GCC 4.8.x is out, the implementation is part of the v3 standard C++ library so it is a different story now.
In an ideal world, the standard library should be like developing for Java - write once, deploy everywhere - but that is not a reality. I would eventually like to move to the standard library implementation rather than Boost's regex and filesystem implementations.
My question given the above regex history, is how should developers use boost, is it possible to do a simple search and replace of the boost headers and namespaces when the features are adopted by the standard library or are there more many things to consider. I would like to use pure C++11 code without dependency on 3rd party libraries.
The amount of work required to move from a Boost library to its C++11 conterpart depends on the degree of C++11 conformance of a particular Boost library. In the simplest case it can be a matter of including another set of headers and using another namespace.
In a more complicated case, Boost library may have some subtle incompliancy with C++11 (eg. in Boost.Thread V1 ~thread used to call detach()) - such things might "silently" break the code correctness, but they are easy to fix.
Finally, Boost library may implement funcionality that doesn't exist in C++11 (eg. boost::bind can be extended using get_pointer function). Apparantly, porting such a code to C++11 would be quite not trivial.
Let's begin with your statement
I would like to use pure C++11 code without dependency on 3rd party
libraries.
It is clear that this is not possible now. You will have to use 3rd party libraries for any non-trivial program.
Unfortunately, C++ with Boost is not a platform also. You need 3rd party libraries to do things available out of the box in languages like Java, C#, Python etc.
So, you have to select libraries according to your requirements: performance, supported platforms, multithreading etc.
Again, Boost shouldn't be your default choice. It is not that useful now as it was 10 years ago. Most of must have stuff went into C++ standard library already.
If you support existing C++ codebase, find the best C++ library for your needs (e.g. re2 for regex). If you start a new project, I would suggest using Qt as a platform.
A "simple" way to migrate usage may be to use preprocessor defines to define a "Using Boost" directive. By putting all boost code in an #if-#else and carefully writing the code to not break (or at least have expected results) for sections that do not have a C++11 equivalent. You can simply not provide a definition for "Using Boost" before at the beginning of your code and C++11 features would be used instead.
See this and this
One link points to an old stackoverflow question, the other to an interesting talk performed by Stephan Lavavej

Should we prefer Boost or standard lib? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm reading Boost array documentation and I see this line :
If you are using C++11, you should consider using std::array instead of boost::array
I was under the impression that Boost, for its major libs, was always preferable to standard lib because :
boost will never perform worse than the standard lib
boost may provide more features
boost is at last of equal quality than standard lib (people writing the C++ standard are active boost developpers/supervisors)
major boost features end up in the standard lib a few years later
So am I right to prefer boost over stdlib ?
If not / more complicated, which of my assumptions are to be corrected ?
I think you should use standard lib when available because... it's standard and comes with the compiler. Besides, if you use boost you need an annoying external dependency.
So, my advice is: use std when possible. If you're writing portable code, that must also be compiled with old compilers, you can consider to use your own namespace (e.g.: cxx0x) that embeds std or boost namespace according to the compiler you're using (this is called namespace alias):
#ifdef COMPILER_HAS_CXX0X
#include <memory>
namespace cxx0x = std;
#else
#include <boost/shared_ptr.hpp>
namespace cxx0x = boost;
#endif
...
cxx0x::shared_ptr<MyClass> = ...
Taken from the Boost people themselves:
Why should an organization use Boost?
In a word, Productivity. Use of
high-quality libraries like Boost
speeds initial development, results in
fewer bugs, reduces
reinvention-of-the-wheel, and cuts
long-term maintenance costs. And since
Boost libraries tend to become de
facto or de jure standards, many
programmers are already familiar with
them.
Ten of the Boost libraries are
included in the C++ Standard Library's
TR1, and so are slated for later full
standardization. More Boost libraries
are in the pipeline for TR2. Using
Boost libraries gives an organization
a head-start in adopting new
technologies.
Many organization already use programs
implemented with Boost, like Adobe
Acrobat Reader 7.0.
From my own experience I prefer to use boost for now. Maybe it's historical, but I found the STD attempts in TR1 that came with VC2008 had too many bugs, in spite of PJ Plauger's best efforts, he couldn't reproduce the quality of the peer-reviewed and checked code of boost that had gone through quite a bit of history.
Unless they can actually take the boost code and use it in STD, why would they reproduce it better? Of course sometimes they might, and really they should work together on it rather than against each other.
One thing I do now though is declare an alias namespace, usually called spns thus:
namespace spns = boost;
after which I can use spns::shared_ptr throughout my code (spns stands for "shared pointer namespace") and if we ever change to std later it will be easy to go to one place and edit just that line and the include.
When it comes to C++11, there are major changes to the Standard and boost's code is C++03. So now the tables are likely to turn for certain parts of the library. I reckon some of boost's fine libraries will become almost obsolete for C++11, e.g. nobody will use boost::lambda anymore, they will just use the new language syntax for a lambda.
So yes, when you move to C++11, it may be time to abandon parts of the boost library and use the new versions.
The trend that I have seen in open source software developed against C++11 is to move API-compatible (subset of) features from STD to boost - because boost is available for non-C++11-compatible compilers where the std features are (obviously) not.
Good example of this is mosh.
For API-compatible features, it's simply a matter of switching namespaces around. In fact, no reason not to make it a configuration option, if you can.
Sidebar: if you're linking against the latest version of non-header-only boost libraries, be forewarned that certain features are no longer available unless boost was compiled with -std=c++11. I ran into this recently with certain functions in the boost::filesystem API.
If something can be standard let it be standard.
If something cannot, use the solution more standard as possible (and BOOST is designed for that)
Many standard library feature are taken from boost, that continue to exist to support application that where deployed when those feature where not yet been standardized.
Using boost for standardized feature is in fact a "look backward". Sometime necessary (may be the standard library specific implementation does not include all what is required ... it is typical to see boost::thread instead of std::thread on windows because of a std implementation not yet been ported by some compilers) but I would not make it a rule.

How well does boost use c++11?

Boost is essentially a c++03 library (which stimulated the c++11 standard). I'm contemplating of using some boost libraries (those that are not implemented in c++11). If I'm using c++11, does boost compile (there may be issues with non-copyable but movable objects)? and how well is boost making use of the c++11 features (variadic templates are an obvious thing to use [by some boost libraries] instead of much of the boost MPL)? (I couldn't find this amongst the boost FAQ).
Boost is moving towards using C++11 features.
But one thing to remember is that boost is not "a library", but rather a collection of libraries. Some of them (for example boost::array) probably won't ever be updated to use many c++11 features. Why should it, when you have std::array in the standard (which was based on boost::array?)
On the other hand, Boost would like to remain useful for people who are still using C++03.
Note: Even though I write as if "Boost" is some monolithic entity, there are lots of people who contribute to boost and they have many different opinions. ;-)
To see how well various boost libraries work with C++11 compilers, you can check out the Boost Testing web page.
C++11 was made do be as backwards compatible as possible. Unless boost is using reserved keywords that are new to C++11, there is no reason I know of why it shouldn't compile just fine with the new standard.

Is complete boost going to be included in C++0x?

Many utilities of boost have been included as part of extended C++ TR1 currently.
Is the complete boost library going to be included once the standard is officially out ? In other words, do I need boost library, if I have complete standard conforming C++11 compiler ?
If not then any reason for that (Reliability cannot be an issue; as far as I know it's written by many people from standard committee) ?
Boost is huge, and of generally high but still varying quality. A lot of the APIs - even the techniques and functionality - are quite "experimental" in the sense that they're still regularly modified as real-world feedback comes in. By way of contrast, the Standard is expected to get it right and need minimal revision, especially when that breaks backwards compatibility.
The standard for review for Standard libraries is much higher than boost's, which is not to say that many boost libraries wouldn't meet the bar - just that many wouldn't too, and that the review process itself is time consuming. There are terrific programmers coordinating and contributing to boost, but they naturally focus their time on their own development interests and things they see as more relevant, so if something is a little specialised, doesn't appeal to their coding style, etc. it may not receive the same scrutiny. The Standard library needs to be scrutinised much more thoroughly as the consequences of change are so much more painful.
While portability is a factor in acceptance of a library into boost, it's not a hard and fast requirement, where-as compiler vendors are expected to make the Standard library run on all C++ compilers, so taking boost more or less as-is and expecting the functionality to be universal on Standard-compliant compiler vendors would put a huge workload on those vendors.
No, in fact very few parts of Boost are "included" in the C++0x revisions to the C++ Standard Library. The parts that are "included" are some of the most commonly used parts of Boost, though.
Really, "included" isn't correct anyway: there are many differences between the Boost libraries and the corresponding additions to the C++ Standard Library. Further, the Boost libraries continue to grow and evolve; the C++0x Standard Library is now finished.
No, Boost is not going to be included in its entirety in C++0x.
Parts of Boost will be, like boost::shared_ptr, Boost.Array, and a couple of other things. But most of Boost is not being included.

what will happen with the overlapping portion of boost once C++0x becomes mainstream?

what will happen with the overlapping portion of boost once C++0x becomes mainstream?
Will boost still contain everything it used to, or will they adapt the library to update it with the new std:: stuff?
Will boost have both a normal c++ version and a c++0x version that they will maintain?
One would hope that Boost continues to support existing classes, for a couple of reasons.
First, there is a body of code that uses the overlapping features in Boost that needs to be supported, for some time.
Second, overlapping implementations allow me to select which one I'd prefer to use. There might be some difference between std::Frob and Boost::Frob that is important to my project, and having a choice is good.
In the long term, though, I would expect a migration toward the standard from both the application writers and the tools providers. That makes it a less risky choice to go with std::.
I am not affiliated with Boost and have no they idea what they will do but it seems like Boost will be left untouched.
There already has been released TR1 (VS 2008 feature pack) and Boost was left untouched. Since many users have not adopted Boost or TR1 yet, my prediction is that for at least next five years boost and c++0x libraries will exist in different namespaces and availaible for C++0x users as well as C++ users.
Namespaces make this somewhat of a non-issue for the Boost developers. There is no direct contention between the boost libraries and the standard libraries because they exist in separate namespaces. Therefore, changes to namespace std (for example the addition of std::tr1) have no direct impact on Boost.
Note however, that if you are importing both libraries (std and boost) into the global namespace, then you will have issues.
The following quote from the Boost TR1 documentation also sheds some light regarding Boost's implementation of TR1 components, suggesting that the corresponding Boost library will be maintained for the foreseeable future:
The TR1 library provides an
implementation of the C++ Technical
Report on Standard Library Extensions.
This library does not itself implement
the TR1 components, rather it's a thin
wrapper that will include your
standard library's TR1 implementation
(if it has one), otherwise it will
include the Boost Library equivalents,
and import them into namespace std::tr1.
Do you mean tr1?
Boost already supports tr1.
All the classes from boost that have been adopted into std::tr1 are available in this namespace from boost. See the following documentation.
http://www.boost.org/doc/libs/1_37_0/doc/html/boost_tr1.html