queue: strengthen type checks

Rewrite some of the macros in a way that:

  a) makes them more likely to trigger compile-time errors if used
     inappropriately, and

  b) makes C++ compilers happy