Search code examples
c++templatesusingctags

Generate ctags in C++ for types masked with using declarations


I am currently working on a project that employs a lot of C++ template metaprogramming. I have a lot of code that looks similar to the following:

template< class T >
struct MakeReferenceImpl{
    using type = T&;
};

template< class T >
using MakeReference = typename MakeReferenceImpl< T >::type;

I often use Vim and have found gCtrl-] to be indispensable for searching tags for symbols but noticed that aliased types generated via using do not receive their own tags (at least not by default). Is it possible to make ctags recognize MakeReference as its own type?


Solution

  • Universal-ctags captures it well.

    $ cat /tmp/input.cc 
    template< class T >
    struct MakeReferenceImpl{
        using type = T&;
    };
    
    template< class T >
    using MakeReference = typename MakeReferenceImpl< T >::type;
    $ ~/var/ctags-github/ctags -o - /tmp/input.cc 
    MakeReference   /tmp/input.cc   /^using MakeReference = typename MakeReferenceImpl< T >::type;$/;"  t   typeref:typename:MakeReferenceImpl<T>::type file:
    MakeReferenceImpl   /tmp/input.cc   /^struct MakeReferenceImpl{$/;" s   file:
    type    /tmp/input.cc   /^    using type = T&;$/;"  t   struct:MakeReferenceImpl    typeref:typename:T &    file: