anon
anon

Reputation: 42617

Basic C++ Idioms / Techniques

Note: marked as community wiki.

In recent days, I've realized how little I know about C++.

Besides:

What other techniques are must-know for a good C++ programmer?

Thanks!

Upvotes: 14

Views: 17984

Answers (6)

baotiao
baotiao

Reputation: 795

The way I used to improve my c++ is reading the source code of leveldb. Because leveldb is a product level code. So you can learn the cpp idiom and design pattern from a real product. Let me show you some example

Leveldb use the Pimpl idiom, almost in all of it's head file, such table.h table_build.h write_batch.h. You can learn from the code directly

Leveldb use many OO design pattern, such as build pattern, the table have the table_build class to build the table, the block have the block_build class to build the block

Leveldb also use the Iterator pattern, the iterator make us use leveldb more convenient.

So I think leveldb contain many idiom or design pattern that c++ engineer should know.

Upvotes: 0

cppist
cppist

Reputation: 659

Basic:

  • RTTI
  • Virtual functions
  • shared_ptr etc
  • Templates
  • Virtual inheriting
  • Variadic macros

Also useful:

  • Attributes (it depends on your compiler)
  • Variadic templates
  • Variadic functions
  • Constexpr (sorting in compile time / calculating hash of strings etc... but the latter is related to the last section)
  • Lambdas

Useful for brainfucking or in special cases:

  • CRTP
  • SFINAE
  • inable_if (type traits)
  • Foreach macro
  • User-defined literals

Upvotes: 2

Peter Alexander
Peter Alexander

Reputation: 54270

I think this should cover it:

More C++ Idioms - Wikibooks

Upvotes: 9

florin
florin

Reputation: 14326

The first two are 'must know' for a good C++ programmer. 'Good C++ programmers' do not overload operators for fun.

Upvotes: 2

Tronic
Tronic

Reputation: 10430

(hardly a must-know, but still useful) Writing domain-specific languages with operator overloading and template metaprogramming (see Boost.Spirit for a nice example) - but this is the kind of thing that makes shooting yourself in the foot easy, too.

Upvotes: 0

dirkgently
dirkgently

Reputation: 111130

  • OO Design
  • Types of exception safety guarantees (which is what most design patterns/idioms are based on).
  • When to use which standard containers
  • Boost

Upvotes: 5

Related Questions