Correct behavior for classes for which only lvalue is convertible to string_view.

Added OnlyLValueString test case that shows the problem with
current impl. Implemented the change, that accept TimeZonePtrOrName
by forwarding reference (to preserve value category), and
merged time_zone selection into one trait.
This commit is contained in:
Tomasz Kamiński
2019-08-06 08:57:50 +02:00
committed by Howard Hinnant
parent 5345d135b7
commit 5a0057587d
2 changed files with 37 additions and 32 deletions

View File

@@ -127,6 +127,15 @@ private:
std::string ms;
};
struct OnlyLValueString
{
OnlyLValueString(std::string s) : ms(std::move(s)) {}
operator std::string_view() & { return ms; }
private:
std::string ms;
};
#endif // HAS_DEDUCTION_GUIDES
@@ -225,5 +234,13 @@ main()
testDeductionFrom<OffsetZone>(std::move(tz));
}
// OnlyLValue
{
OnlyLValueString tz("Europe/Warsaw");
testDeductionFrom<time_zone const*>(tz);
//testDeductionFrom<time_zone const*>(to_const(tz));
//testDeductionFrom<time_zone const*>(std::move(tz));
}
#endif // HAS_DEDUCTION_GUIDES
}