C / C++ equivalents to the Python Standard Library - c++

I depend heavily on Python's standard library, both for useful data structures and manipulators (e.g., collections and itertools) and for utilities (e.g., optparse, json, and logging), to skip the boilerplate and just Get Things Done. Looking through documentation on the C++ standard library, it seems entirely about data structures, with little in the way of the "batteries included" in Python's standard library.
The Boost library is the only open-source C++ library collection I know of that resembles the Python standard library, however while it does have utility libraries such as Regular Expression support, most of it is also dedicated to data structures. I'm just really surprised that even something as simple as assured parsing and writing a CSV file, made delightfully simple with the Python csv module, looks to require rolling-your-own in C++ (even if you leverage some parsing library by Boost).
Are there other open-source libraries out there for C++ that provide "batteries"? If not, what do you do as a C++ programmer: hunt for individual utility libraries (and if so, how), or just roll your own (which seems annoying and wasteful)?

The Poco library is more like other languages' standard libraries.
Actually the Poco web site's logo says "C++ now comes with batteries included!", which seems to be precisely what you're asking for.
I didn't like it when I tried because I found it too C-like and with too many dependencies between parts (difficult to single out just the functionality you want).
But there are many people & firms using it, so it seems I'm in minority and you will perhaps find it very useful.
In addition, as others have mentioned, for data structures, parsers, and indeed an interface to Python!, and such stuff, check out Boost.
Cheers & hth.,

While C++ does offer many of the comforts extended by OO it keeps a very simple standard library. C++ has STL and Boost. These are very good, and have more then just datastructures.
If your needs are these sorts of higher order functions for prototyping or making application without intense (relative term) speed requirements then C/C++ is probably not the right choice for you. I believe you will find that for most projects that high level languages will be fast enough for your needs. If you are working on an application that requires C/C++ speed (and accompanying standard deviations) then you should probably invest your time carefully picking each individual library you will be using.

http://beta.boost.org/community/sandbox.html
http://www.boostpro.com/vault/
also you can google for "boost+bar", eg
boost log ->
http://boost-log.sourceforge.net/libs/log/doc/html/index.html
boost threadpool ->
http://threadpool.sourceforge.net/

http://www.boost.org/doc/libs/1_45_0/?view=categorized
Boost isn't just about data structures - it has lots of the batteries you want - parsing, threads, collections, logging, etc.

With C and C++ you typically won't find a "do it all" library, instead you'll use individual libraries that do different things. You can use one library that does JSON parsing, one that does crypto, one that does logging, etc.
Boost and Qt are the only ones that would be more of a "do it all" type library.

Related

Boost library acceptance in industry

I have seen lots of people suggesting the Boost library on Stack Overflow, so I am also thinking of learning it. But today I came across this link: http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Boost
I wanted to know about its acceptance in industry at a broader level. My current company also doesn't allow me to use this so I am confused whether to look into this or not.
Parts of Boost library is currently being accepted into the Standard library for C++0x and it is regarded as one of the top libs with a high industry acceptance. I'm actually unaware of any other library getting accepted into the C++ Standard Library on such a large scale.
"Ten Boost libraries are already included in the C++ Standards Committee's Library Technical Report (TR1) and will be in the new C++0x Standard now being finalized. C++0x will also include several more Boost libraries in addition to those from TR1. More Boost libraries are proposed for TR2."
You should definately look into this. Don't go by Google or any other large institution. They generally have to work to a subset of any complex language like C++. Hence, they'll have restrictions on which parts they can use so that it's easier to hire and train engineers to use the code base.
Additionally, Boost leverages many aspects of the higher forms of functionality within C++, case in point template meta-programming. Boost provides for a safer, though bulkier, form of functions as first class objects. They add in a more powerful "bind" which works so well with the standard library that I'd be lost without it. Finally, they have in place tuples and hash tables, both fundamental datatypes in modern development libraries.
In short, I really can't name one reason why you wouldn't want to look at Boost, even just to learn something. It's peer reviewed and largely platform independent. The source code is a treasure trove of information and more advanced programming techniques.
I think the who is using boost web page speaks for itself. Notably: Adobe, McAfee, and Real Networks probably qualify as industry.
My current company also does not allow me
to use [boost]. So I am confused whether
to look into it or not.
You might want to dig a little further and find out why. As others have said, Boost is a fantastically useful set of open source and peer reviewed libraries of extremely high quality. Look at their development LOC chart for an idea how long and how much $$ it would cost your company to reinvent the wheel.

Whats the most basic way to go online in c++?

What is the most basic way to go to a webpage and download its contents? the webpage i wish to get only has text, most of which is in tables.
is there a std library that does it (like urllib in python)?
There's no official C++ network library, no. There are many different APIs available, though. Which is best for you would depend on what platform(s) you were targeting and what framework(s) you might already be using.
That said, cpp-netlib is a platform-neutral API that follows C++ idioms nicely. I've used it and it works.
A large number of tasks that are not covered by the C++ standard library can be done using boost, the collection of peer-reviewed portable libraries, which are used by pretty much every C++ project today. For networking, we use boost.asio.
Their tutorials include HTTP clients: http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/example/http/client/sync_client.cpp and http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/example/http/client/async_client.cpp
However, although this is highly portable and may end up becoming part of the C++ standard library in future, it is a bit too low-level for your task. libCURL is the today's default library for HTTP downloads.

C++ standard API

I am a student, and new to C++. I am searching for a standard C++ API that is as comprehensive as the Java API. So far I have been using cplusplus.com, and cppreference.com.
Please any help would be greatly appreciated.
C++ and Java have very different standard libraries because they make very different assumptions about what they are going to be used for.
Java assumes that applications or applets will be running on a host with a full featured OS, with a defined way of doing most normal things.
There's a lot of content in that, for instance, in java, the output will be an application or applet. C++ does not make that assumption, because C++ can be used for building OS Kernels and drivers for kernels, it can be used for programming full stack real time applications on microcontrollers, or processing blocks in supercomputers.
C++ can be used for implementing the very operating system on which it will run.
For these reasons, the standard library assumes almost nothing about what it will have available, and so the standard library doesn't make any dependencies on those features.
The only exception is with files and streaming, because almost any operating system like stack has something that looks like a file stream if it has anything like files at all.
If you want a richer set of OS Specific api's you need to look at something non-standard. A great choice is the Qt framework, which provides many tools similar to what is found in the Java libraries, is cross platform, and works well with native C++ idioms.
C++ has a standard library.
You can try reading the "The C++ Standard Library: A Tutorial and Reference". While I don't own it myself, it's on our book list (which I recommend you check out), so it shouldn't be bad.
Note C++ isn't Java, so the libraries don't necessarily have the same functionality. Another resource you'll want to look at is Boost, which serves as a source for well-written C++ libraries for things the standard library lacks.
GNU C++ Standard library documentation is the one I refer to most often.
Java is a virtual machine language and as such attempts to have a comprehensive api to provide a platform independent method of drawing/wrtinging to files / anything. IN the guts of JRE they are taking these generic inputs and using them to do platform specific things. In C++ you are the one that does that work. Many c++ libraries are platform specific see MFC, ATL or code that is written for XWindows it your job to decide how you want to implement a feature and see if that is a platform specific feature or can be done in a platform independent manner.
If you are writing on windows or unix I can assure that the OS API is very complete and will allow you to do what ever your trying to accomplish. Also take a look at cross platfom libraries like lib qt.
Java's standard library is aimed at providing ready-to-use functionality, while the C++ standard library is aimed at providing building blocks that aren't defined by the core language. The Boost library has mainly the same orientation as the standard library (with a few exceptions such as image processing). I think the closest you can get to something like Java's standard library is the Poco library.
However, when I tried on the Poco library I found that it was a bit too C-oriented for my taste.
That is, it's not "modern". You get that impression straight away without even looking at the APIs, because the online docs uses 1990's frames. :-) However, it may fill your needs.
If you mean the c++ standard library I'd look at www.cplusplus.com. It covers the current standards. After familiarizing yourself with that, you could try looking at boost.
There are a number of changes in the upcoming c++0x standard. Wikipedia has info on a number of these as does SO.
The number one book, IMO, for c++ is Effective C++ by Scott Meyers.

C++ Libraries similar to C#?

I'm coming to C++ from a .Net background. Knowing how to use the Standard C++ Libraries, and all the syntax, I've never ventured further. Now I'm looking learning a bit more, such as what libraries are commonly used? I want to start getting into Threading but have no idea to start. Is there a library (similar to how .net has System.Threading) out there that will make it a bit easier? I'm specifically looking to do Linux based network programming.
For C++, Boost is your everything. Threading and networking are among the things it offers. But there's much more:
Smart pointers
Useful containers not found in the STL, such as fixed-size arrays and hashtables
Closures
Date/time classes
A foreach construct
Min/max functions
Command line option parsing
Regular expressions
As the others have said, Boost is great. It implements the C++ Technical Report 1 in addition to tons of other stuff, including some mind-blowing template metaprogramming tricks.
For other cross-platform features not provided by Boost, I've had very good luck with a library called Poco. I've worked on commercial projects that incorporated its simple HTTP server, for instance, and it treated us quite well.
lots of boost suggestions, but Qt is another good option. It's got great support for threading and networking along with pretty much everything else.
http://qt.nokia.com/products
If you are looking into network programming and are not interested into GUI, I suggest Boost libraries: in particular, Asio.
There's no standard multithreading library, but the boost library includes a platform-independent multithreading abstraction that works very well.

Cross-platform C++ command line utility

I need to develop a Windows/Linux command line utility. The utility will talk to middleware that has a standard API on both platforms. I have done some cross-platform development before, on FreeBSD/Linux, which was considerably easier - and I had people in the group with experience that I could talk to.
At this point there is no one in my group who has tackled a Windows/Linux development project. I am looking for advice on how to best set it up. I'm kind of a newbie to C++ too, I have mostly developed C#/.Net GUI applications and Linux device driver level "stuff". Kind of a weird mix.
I was thinking that it would be best to define my own data types and not use either the Linux or the Windows defined types - keep the OS specific code in separate folders and include conditionally. That's kind of what we did for the Linux/BSD work. So it seemed like a good start.
One of the developers here is a big fan of Boost... another thought the TCLAP command line parser library was easier to use... Obviously everything has to be compatible with the licensing.
The code will be open sourced, but it is production code - so I don't want to be sloppy. What else should I be doing or looking for? Are there any best practices out there?
Boost is good, as is ACE. Between the 2 of those they cover pretty much anything you would want to do in a cross-platform manner. I have also gone the route of getting posix libraries for windows and using gcc on cygwin, but I don't recommend it.
Use a portable runtime that is supported on both platforms. I have had good luck with the Apache Portable Runtime.
Use standard C or C++ for most of the project. Only use platform specific functions when necessary. If possible, put those in a wrapper in isolated files so that the build (makefile) can substitute in the correct version for the appropriate platform.
Refrain from using #ifdef LINUX or #ifdef WINDOWS or similar conditional compilation. Those get really hard to debug and there are error prone when the keyword is not supplied to the compiler.
Use Boost. Among other things, you'll get a portable implementation of a subset of TR1, which is worth it if only for <cstdint> and the types within - int32_t etc. As well, shared_ptr is essential for many moderately complicated data structures.
Boost also has a slew of helper types which are extremely convenient in day-to-day C++ tasks. Two specific ones that come to mind right away are optional, and ptr_... polymorphic container types come to mind right away. String algorithm library is also very handy, considering the lack of very commonly needed string functions, such as case conversion or trimming, in the standard library.
Speaking of more heavyweight components, Boost.Filesystem is a very decent cross-platform abstraction for filesystem navigation, also a relatively common task in command-line tools. Then there's Boost.MultiIndex is a swiss army knife of containers - rarely truly needed, but when it is, it's indispensable.
I did a gig this summer in .NET and just ported to Mono. Worked great.
Although there are some good cross platform libraries out there (like Boost), remember that they are probably not there by default. This is especially problematic if you are shipping binaries only. The target platform is unlikely to have the library (or correct version of the library) that you need.
First prize is to stick with standard C++ (even if you need to implement simple stuff yourself). This avoid library dependence altogether.
If you must use a library, try statically linking against it (although this may create big binaries). This will allow you to avoid runtime failure due to lack of binaries.
If you must ship DLLs (or .so on some unixes) make sure that the correct version is shipped with your product and some way to avoid conflicts with the wrong version.
If you are shipping code, include the library with the code and build the library as well as your utility.
Also beware of GPL and possibly LGPL code. If you release a library with a GPL dependency (or modify an LGPL library) you will need to supply the code and allow redistribution as per the GPL.
TCLAP is the only header-only CLI parsing option that I'm aware of. As such, it strikes me as the most portable and is probably your best bet (it's currently what I use and recommend for exactly those reasons). It also helps that the API for TCLAP is very developer friendly and automatically generates decently formatted help messages for you.
Boost program_options has a shard library component to it, which is irritating to maintain ABI with. It also gets around nuisance parsing incompatibilities and behaviors from the getopt family of arguments.
I have used libparamset, that is cross platform (Windows, OS X, Linux) CLI parser. It provides flexible and powerful CLI parser and various UI building features (input error handling, wildcards, typo detection, task resolving, help formatting ...) to build a good command-line tool. It is suitable for both C and C++ projects.