As it is now, it can be really difficult to debug misuse of the library. A misunderstanding of the various algorithms or improperly tracking the form of the data being operated on leads to inscrutable template errors. Meticulously examining the compilation error can sometimes help in resolving the issue, but it can also lead to further confusion. For example, Clang does not show the value of the parameter pack at each alias template call.
I get that fast evaluation is important to this library. However, use of this library frequently leads to near-impossible to debug metaprograms.
A proposal for easier debugging: a KVASIR_MPL_DEBUG preprocessor define which unlocks static asserts, the goal being easier to understand compilation errors.
For example, front<> could do something like this when #ifdef KVASIR_MPL_DEBUG:
template <typename... Ts>
struct checked_front {
static_assert(sizeof...(Ts) > 0, "a nice error message about needing at least one argument");
};
template <typename T, typename... Ts>
struct checked_front<T, Ts...> {
using type = T;
};
template <...>
struct front {
template <typename... Ts>
using f = typename checked_front<Ts...>::type;
};
While I don't like having two forms for every algorithm, I think that these asserts can be designed to be transparently inserted into the calls in some form of continuation. Maybe some kind of peek<...> continuation which calls the appropriate static asserts. peek<check_front, ...>
As it is now, it can be really difficult to debug misuse of the library. A misunderstanding of the various algorithms or improperly tracking the form of the data being operated on leads to inscrutable template errors. Meticulously examining the compilation error can sometimes help in resolving the issue, but it can also lead to further confusion. For example, Clang does not show the value of the parameter pack at each alias template call.
I get that fast evaluation is important to this library. However, use of this library frequently leads to near-impossible to debug metaprograms.
A proposal for easier debugging: a
KVASIR_MPL_DEBUGpreprocessor define which unlocks static asserts, the goal being easier to understand compilation errors.For example,
front<>could do something like this when#ifdef KVASIR_MPL_DEBUG:While I don't like having two forms for every algorithm, I think that these asserts can be designed to be transparently inserted into the calls in some form of continuation. Maybe some kind of
peek<...>continuation which calls the appropriate static asserts.peek<check_front, ...>