Krystian's Q2 2024 Update

Jul 15, 2024

MrDocs

This quarter, my primary focus was on MrDocs. To that end, I’m happy to say that the P0 milestone for MrDocs has been reached! Although the vast majority of the work I did was bug hunting/fixing, I also implemented a novel feature which detects and simplifies types that use the SFINAE idiom.

Prior to C++20, the primary mechanism for constraining templates was through use of the SFINAE idiom, e.g.:

template<typename T>
std::enable_if_t<std::is_pointer_v<T>, T> f(T); // only viable when T is a pointer type

These kinds of constrained declarations can be rather “noisy” due to the constraints being written into the type of the declaration. One solution is to use macros to show the simplified type when generating documentation:

template<typename T>
#ifndef DOCS
std::enable_if_t<std::is_pointer_v<T>, T>
#else
T
#endif
f(T);

but this requires manual intervention on the part of the library author. Since MrDocs generates documentation using the clang AST, we can detect whether a template implements the SFINAE idiom and show the “replacement type” instead:

template<typename T>
std::enable_if_t<std::is_pointer_v<T>, T> // rendered as 'T' in the documentation since std::enable_if_t is a SFINAE template
f(T);

In general, MrDocs determines whether a type naming a member M of a class template C uses the SFINAE idiom by identifying every declaration of M in the primary template and every partial/explicit specialization of C. If M is not found in at least one of the class definitions, and if every declaration of M declares it as an alias for the same type as every other declaration, then C is a template implementing the SFINAE.

Clang

In addition to working on MrDocs, I merged a number of clang patches this quarter:

All Posts by This Author