Very easy question but I've got so used to finding boost functionality as part of STL in C++11 that I was surprised when I couldn't see a join function.
Just to double check - it's definitely not present in C++11? Is it part of any newer versions of the C++ standard?
There is no std::join in C++11 or C++14 so you will still have to use the boost version. There is an open proposal for it N3954
Accorging to http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/sd-1.htm The papper has been mailed out and is in the "Library Evolution" sub group.
Related
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.
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
I'm trying to get my program working without boost usage, but can't find an alternative of some useful patterns. Namely, I can't find boost::optional-likewise pattern in the standard library. Is there some standard alternative for boost::optional (C++11 or somewhere else)?
Short answer: No.
Long answer: Roll your own according to the boost spec. The documentation is quite exhaustive and the code isn't that complex, but this still requires above average C++ skills.
To update this answer: C++14 unfortunately did not ship with std::optional. The current proposal (Revision 5) is N3793 and it is expected to be shipped as a separate technical specification or to become part of C++17.
There is currently a proposal for C++14 (or C++17). So the answer is (probably) not yet :).
Like pmr explained, it is not possible right now, and will not be until C++17 is out.
However, you should be able to use this single header library on github as a drop in replacement of boost- or std optional. It has no dependencies (except a c++11/c++14 capable compiler).
I would like to use std::array, std::regex and other things that are new in C++11.
Does clang already support C++11?
Yes but not everything. Check out this status page; it's updated very frequently. It's the current source code (work in progress) state, not the last release state, so check the version in the table to be sure it corresponds to what you have.
For standard library features, checks the links at the end of the page, depending on which context you are in.
Also, the Apache wiki includes this table summarizing C++11 features and their support in popular compilers.
The parts of C++11 that you're looking for are actually part of the standard library. If you're using the clang compiler, you'll want to use the libc++ standard library, which has support for most of C++11 and works really well with clang.
Is anyone using the GCC 4.4.0 C++0x support in production? I'm thinking about using it with the latest MinGW, but I'm not sure if it's mature enough.
I'm interested in:
TR1 support
auto
initializer lists
IMHO, TR1 support and auto are safe to use. In the case of auto it was one of the first features to be included into the standard and is a relatively small change to the language. I would therefore have no problem using it.
I would be a bit more hesitant about using initializer lists. On some other forums (eg. comp.lang.c++.moderated) there are questions about their behaviour and its possible that they may change closer to the release of the standard.
I'm not using GCC 4.4.0 C++0x support in production but I'm using the TR1 features with the help of the Boost Library http://www.boost.org/.
The Boost Library is well tested and often used in production environments. If you convert to the C++0x standard later the only thing you have to do is changing your include Directives http://www.boost.org/doc/libs/1_40_0/doc/html/boost_tr1.html.
In my opinion it's currently better to use the Boost Library until the standard is finished. It's a much more compiler independent way.
MinGW simply won't compile with '-std=c++0x'. Strange enough, '-std=gnu++0x' works. Anyway it seems buggy and I won't count on it.