Expected<T>é implementado em llvm / Support / Error.h. É uma união com tags que contém a Tou an Error.
Expected<T>é uma classe de modelo com o tipo T:
template <class T> class LLVM_NODISCARD Expected
Mas esses dois construtores realmente me confundem:
/// Move construct an Expected<T> value from an Expected<OtherT>, where OtherT
/// must be convertible to T.
template <class OtherT>
Expected(Expected<OtherT> &&Other,
typename std::enable_if<std::is_convertible<OtherT, T>::value>::type
* = nullptr) {
moveConstruct(std::move(Other));
}
/// Move construct an Expected<T> value from an Expected<OtherT>, where OtherT
/// isn't convertible to T.
template <class OtherT>
explicit Expected(
Expected<OtherT> &&Other,
typename std::enable_if<!std::is_convertible<OtherT, T>::value>::type * =
nullptr) {
moveConstruct(std::move(Other));
}
Por que Expected<T>repetir duas construções para a mesma implementação? Por que não faz assim ?:
template <class OtherT>
Expected(Expected<OtherT>&& Other) { moveConstruct(std::move(Other));}
explicitpalavras-chave são importantes aqui? Alguém poderia dar um exemplo?
explicitpalavra