Out of pure laziness, I decided to create lstlisting floats with the option offered by the package:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[float,caption={Test}]
void a() {
foo();
}
\end{lstlisting}
\end{document}
This creates a float in which the code is left aligned:

This looks just silly on a page with text if code lines are short.
Of course, it's easy to center by creating "regular" figures (maybe with a custom type for listings), but this approach here has the appeal of brevity.
Is there a way to get the code centered in this setup?
