+ UnicodeString result = output.getStringRef().toUnicodeString();
+ return appendTo.append(adjustForContext(result));
+}
+
+template<typename F, typename... Args>
+FormattedRelativeDateTime RelativeDateTimeFormatter::doFormatToValue(
+ F callback,
+ UErrorCode& status,
+ Args... args) const {
+ if (!checkNoAdjustForContext(status)) {
+ return FormattedRelativeDateTime(status);
+ }
+ LocalPointer<FormattedRelativeDateTimeData> output(
+ new FormattedRelativeDateTimeData(), status);
+ if (U_FAILURE(status)) {
+ return FormattedRelativeDateTime(status);
+ }
+ (this->*callback)(std::forward<Args>(args)..., *output, status);
+ output->getStringRef().writeTerminator(status);
+ return FormattedRelativeDateTime(output.orphan());
+}
+
+UnicodeString& RelativeDateTimeFormatter::format(
+ double quantity,
+ UDateDirection direction,
+ UDateRelativeUnit unit,
+ UnicodeString& appendTo,
+ UErrorCode& status) const {
+ return doFormat(
+ &RelativeDateTimeFormatter::formatImpl,
+ appendTo,
+ status,
+ quantity,
+ direction,
+ unit);
+}
+
+FormattedRelativeDateTime RelativeDateTimeFormatter::formatToValue(
+ double quantity,
+ UDateDirection direction,
+ UDateRelativeUnit unit,
+ UErrorCode& status) const {
+ return doFormatToValue(
+ &RelativeDateTimeFormatter::formatImpl,
+ status,
+ quantity,
+ direction,
+ unit);
+}
+
+void RelativeDateTimeFormatter::formatImpl(
+ double quantity,
+ UDateDirection direction,
+ UDateRelativeUnit unit,
+ FormattedRelativeDateTimeData& output,
+ UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return;
+ }