Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What components are essential to a C++ project which are not found in a common library? [closed]

Tags:

c++

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.

like image 206
pmr Avatar asked Nov 01 '25 01:11

pmr


2 Answers

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.

like image 171
John Dibling Avatar answered Nov 02 '25 16:11

John Dibling


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)
like image 25
Frunsi Avatar answered Nov 02 '25 15:11

Frunsi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!