Expected<T>ist in llvm / Support / Error.h implementiert. Es ist eine getaggte Vereinigung, die entweder ein Toder ein hält Error.
Expected<T>ist eine Vorlagenklasse mit dem Typ T:
template <class T> class LLVM_NODISCARD Expected
Aber diese beiden Konstruktoren verwirren mich wirklich:
/// 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));
}
Warum werden Expected<T>zwei Konstrukte für dieselbe Implementierung wiederholt? Warum macht es das nicht so?:
template <class OtherT>
Expected(Expected<OtherT>&& Other) { moveConstruct(std::move(Other));}
explicitKeywords hier wichtig sind. Könnte jemand ein Beispiel geben?
explicitSchlüsselwort