Adapted once snippet for c++-mode for my purposes.