I’m gonna try to summarize my understanding of this to make sure I actually got it right.
We want this specialization of CustomBuildField
for (most) of our serializable types. So we can either define it manually for each type or we can make use of sfinae (like you do here) to automatically only create the specialization for each of the required serializable types.
We also want to be able to further overload CustomBuildField
for serializable types that can’t use this generic specialization (e.g. if we need to use TX_WITH_WITNESS
), so we specify Priority<1>
such that another overload with Priority<2>
would take precedence.
What I don’t understand is making this exclusive to non cv and reference qualified types.
If LocalType is cv or reference qualified, it is important to fall back to lower-priority Priority<0> … to prevent this CustomBuildField overload from taking precedence
As I understand it, this comment implies that (without && std::is_same_v<LocalType, std::remove_cv_t<std::remove_reference_t<LocalType>>>
) the following would not take precedence, even though it has Priority<2>
?
0template <typename LocalType, typename Output>
1void CustomBuildField(TypeList<LocalType>, Priority<2>, InvokeContext& invoke_context, const CTransaction& value, Output&& output)
2{
3 DataStream stream;
4 stream << TX_WITH_WITNESS(value);
5 auto result = output.init(stream.size());
6 memcpy(result.begin(), stream.data(), stream.size());
7}