Commit 40fb25b3 authored by Alexander Kindyakov's avatar Alexander Kindyakov Committed by Facebook Github Bot

Fix up typo in tryTo<> for enums

Summary: This diff fixes the typo in `tryTo` declaration for `enum`s and adds test coverage for enum specialization.

Reviewed By: yfeldblum, shixiao

Differential Revision: D8694574

fbshipit-source-id: d20e34d7d7bae7805cc7c31507cffb292235bdfc
parent 327cac1e
......@@ -1561,8 +1561,8 @@ tryTo(const Src& value) {
template <class Tgt, class Src>
typename std::enable_if<
!std::is_convertible<Src, StringPiece>::valuea &&
std::is_enum<Tgt>::value && !std::is_same<Src, Tgt>::value,
!std::is_convertible<Src, StringPiece>::value && std::is_enum<Tgt>::value &&
!std::is_same<Src, Tgt>::value,
Expected<Tgt, ConversionCode>>::type
tryTo(const Src& value) {
using I = typename std::underlying_type<Tgt>::type;
......
......@@ -1294,3 +1294,21 @@ TEST(Conv, TryToThenWithVoid) {
Unit u = x.value();
(void)u;
}
TEST(conv, TryIntToUnscopedEnumAndBack) {
enum UnscopedEnum {
First = 0,
Second = 1,
};
EXPECT_EQ(UnscopedEnum::Second, folly::tryTo<UnscopedEnum>(1).value());
EXPECT_EQ(1, folly::tryTo<int>(UnscopedEnum::Second).value());
}
TEST(conv, TryIntToScopedEnumAndBack) {
enum class ScopedEnum {
First = 0,
Second = 1,
};
EXPECT_EQ(ScopedEnum::Second, folly::tryTo<ScopedEnum>(1).value());
EXPECT_EQ(1, folly::tryTo<int>(ScopedEnum::Second).value());
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment