tags:

views:

157

answers:

8

For most C++ projects Boost covers a lot of ground component wise but often used solutions and idioms require some boiler plate or ground work. What do you consider so essential that you would have it in every project and thus have it in a small "library"? Some things I thought of:

  • Singleton base-class (somebody will think he needs it, so he can do it properly)
  • ScopeGuard
  • Factory base-class
  • any_iterator

(The last two are in Loki but Loki has overlap with Boost and people are hesitant to use it.)

Edit: I might should add that I don't ask about the usual extensions of the standard library e.g. copy_if.

+2  A: 

Maybe I don't write the sheer volume of code as other people (been using C++ professionally for six years), but I'm going with: nothing. Any time I've wished an idiom was in the standard library or Boost, that's a clue that maybe it isn't the best way to go. Often times you can express your concepts more simply by rewriting them to take advantage of existing constructs. Good code is easy code. Let the geniuses behind Boost take care of the complicated stuff for you.

Kristo
A: 

Ring or circular buffer. This an often used data structure in Embedded Systems.

Thomas Matthews
+1  A: 

My small library, that I carry along with most projects contains very practical tools:

  • assert utilities (release & debug assert with a user dialog with details and buttons for "start debugger", "ignore this assertion", "always ignore..")
  • Buffer utilities to avoid working with "plain" heap arrays (class HeapBuffer and class SharedHeapBuffer with ref counting)
  • logging facilities
  • UTF8 / UCS2 encode/decode
  • configuration utilities (class CfgValue with one-liner string-to-number/bool conversion methods)
  • some fast string to number and number to string routines
  • fast float to int conversion routines
  • explode/implode numbers/strings on separator utilities
  • ini file parser & writer
  • timer class and some quick&dirty profiling tools
  • mutexes, conditions, r/w-locks, multi-threading utilities (but from time to time I replace more and more of that with boost locks and thread utilities)
  • a lightweight messaging system "construction kit" (messages, ports, sender, handlers, sinks, dispatchers, routers, threaded sinks, threadpool sinks and so on)
frunsi
A: 
Sam Miller
All you've listed are common libraries, so it seems you haven't really answered the question at all.
Rob Kennedy
A: 

logging class (that also works in a Gui)

Martin Beckett
A: 

An encryption library or two wrapped up in a nice interface.

Hashing algorithms can also be quite useful.

DanDan
+5  A: 

None of the above. In particular, definitely not a Singleton class, since the use of Singletons are typically an indication of a design flaw. In the past 15 years, I have never needed a Singleton class and all those that I have found in my travels were hacks or otherwise compromised the robustness of the system they were in.

Generally speaking, aside from a good, Standards-compliant compiler, a desire to never stop learning more about my language of choice and coding standards that don't restrict my movements, I have found that I need nothing in order to write complete systems.

Of particular note, over the past 15 years every job I've had has specifically forbidden the use of Boost. Although I use Boost in my own projects and in little tools I hack up, none of my production code uses it. I am a fan of Boost, but I haven't really missed it. And now with the C++0x support in VS2010, I miss it even less.

That said, over the years I have cooked up an #include library that I take with me wherever I go of useful little things and gizmos. It includes:

  • An exception framework
  • A version of sprintf that works with std::string
  • A high-resolution timer class which I use primarily for development, stress testing & debugging
  • An implementation of transform_if
  • An implementation of copy_if

And a few other STL extensions which I use very rarely.

John Dibling
I've built up a similar toolbox, which also includes pretty printing for STL containers (I want to be able to dump them), a Pimpl template implementation and other facilities. Note that `copy_if` made it to C++0x if I am not mistaken. Finally, I am certainly very sad to see that Boost isn't used. It's quite difficult to go without `boost::shared_ptr` in multithread, and I certainly pass reimplementing it...
Matthieu M.
+2  A: 

None of the ones you suggested.

A singleton is a horrible antipattern, and the last thing I'd want in my C++ programs is more of them. And if you use RAII consistently for your own classes, you don't really need a separate ScopeGuard class.

A factory base-class? What exactly would it do? I don't really see enough common functionality between factories that it'd be worth putting in a single universal base class.

And I'm not really sure what you mean by an any_iterator. :)

The things that are essential to a C++ project are the ones people put in libraries. And if something is not in any of the common libraries, then it is because it is not commonly needed (or because it has to be customized for the individual project, so a library version has little value)

So your question could basically be rephrased as "what would be an obvious addition to popular libraries, which hasn't already been added to them", and the answer, just as obviously, is "nothing, because if the idea was obvious, the library writers thought of it as well, and so they already added it"

jalf
I mostly agree, but there are things that are not appropriate to be wrapped in a library: any kind of utility that matures with the experience of the developer.. e.g. things like assert utilities (the standard assert is too impractical), messaging systems, any kind of "lightweight abstraction" that is "good enough", but not (yet) general enough to be wrapped up in a library.
frunsi