[Tex/LaTex] Conditionally print subsection in Beamer

beamersectioning

I've ported from PowerPoint my university's template in Beamer, and added some code to display sections (and subsections when they exists) in the header.

This is the code snippet I've put in the headline template for this purpose:

\begin{beamercolorbox}[wd=0.6\paperwidth,ht=0.1\beamer@PoliMI@headheight]{section in head/foot}%
    \usebeamerfont{section in head/foot}\par%
    \vfill\strut\insertsectionhead%
    \ifx\insertsubsection\empty\else%
    ~--~\insertsubsectionhead%
    \fi%
    \strut\par%
\end{beamercolorbox}\\%

However, when "exiting" from subsection (issuing \subsection*{}), the dash after the section name is still printed.

How can I test if the subsection name is void?
As an alternative, how can I make \insertsubsection empty?

MWE:

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}\normalfont
\usepackage[T1]{fontenc}

\setbeamertemplate{navigation symbols}{}

\setbeamertemplate{headline}{%
  \begin{beamercolorbox}[wd=0.6\paperwidth,ht=0.016\paperwidth]{section in head/foot}%
    \usebeamerfont{section in head/foot}%
    \par\vfill\strut\insertsectionhead%
    \ifx\insertsubsection\empty\else~--~\insertsubsectionhead%
    \fi\strut\par%
  \end{beamercolorbox}%
}

\begin{document}
 \section{aaa}
  \begin{frame}~\end{frame}
  \subsection{bbb}
   \begin{frame}~\end{frame}
  \subsection*{}
   \begin{frame}~\end{frame}
\end{document}

In the third frame, only "aaa" must show up, and not "aaa -".

UPDATE: If subsection is not yet defined, \insertsubsection is empty, whereas if a \subsection*{} is issued, the macro is expanded in \expandafter \hyperlink \subsectionlink, either the subsection is empty (\insertsubsectionhead expands to \hyperlink {Navigation\the \c@page }{}) or not (\insertsubsectionhead expands to \hyperlink {Navigation\the \c@page }{bbb} in the second frame).

Best Answer

I have replaced the code snippet with

\ifx\insertsubsection\empty\else%
 \ifdefempty{\subsecname}{\relax}{%
  ~--~\insertsubsectionhead%
 }%
\fi

and IT WORKS!!!
Unfortunately needs the etoolbox package to be loaded...

EDIT:

\setbox0=\hbox{\subsecname\unskip}\ifdim\wd0=0pt\else%
 ~--~\insertsubsectionhead%
\fi%

also works and does not require etoolbox.
I don't know if this is the "cleaner" solution.