specialize std::hash for enum classes
Summary: This diff fixes the compilation error: "implicit instantiation of undefined template std::hash" when using TextAttributes in Android Reviewed By: shergin Differential Revision: D9849407 fbshipit-source-id: 7fcb94b1d4f7715d8037ecbf302d8f345e99e9fd
This commit is contained in:
parent
9ad193c35b
commit
c97faa2560
|
@ -7,6 +7,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
|
@ -81,6 +85,7 @@ enum class TextDecorationLineStyle {
|
|||
Double
|
||||
};
|
||||
|
||||
|
||||
enum class TextDecorationLinePattern {
|
||||
Solid,
|
||||
Dot,
|
||||
|
@ -89,6 +94,90 @@ enum class TextDecorationLinePattern {
|
|||
DashDotDot,
|
||||
};
|
||||
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <>
|
||||
struct hash<facebook::react::FontVariant>
|
||||
{
|
||||
size_t operator()(const facebook::react::FontVariant& v) const
|
||||
{
|
||||
return hash<int>()(static_cast<int>(v));
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<facebook::react::TextAlignment>
|
||||
{
|
||||
size_t operator()(const facebook::react::TextAlignment& v) const
|
||||
{
|
||||
return hash<int>()(static_cast<int>(v));
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<facebook::react::FontStyle>
|
||||
{
|
||||
size_t operator()(const facebook::react::FontStyle& v) const
|
||||
{
|
||||
return hash<int>()(static_cast<int>(v));
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<facebook::react::TextDecorationLineType>
|
||||
{
|
||||
size_t operator()(const facebook::react::TextDecorationLineType& v) const
|
||||
{
|
||||
return hash<int>()(static_cast<int>(v));
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<facebook::react::WritingDirection>
|
||||
{
|
||||
size_t operator()(const facebook::react::WritingDirection& v) const
|
||||
{
|
||||
return hash<int>()(static_cast<int>(v));
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<facebook::react::TextDecorationLinePattern>
|
||||
{
|
||||
size_t operator()(const facebook::react::TextDecorationLinePattern& v) const
|
||||
{
|
||||
return hash<int>()(static_cast<int>(v));
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<facebook::react::TextDecorationLineStyle>
|
||||
{
|
||||
size_t operator()(const facebook::react::TextDecorationLineStyle& v) const
|
||||
{
|
||||
return hash<int>()(static_cast<int>(v));
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<facebook::react::FontWeight>
|
||||
{
|
||||
size_t operator()(const facebook::react::FontWeight& v) const
|
||||
{
|
||||
return hash<int>()(static_cast<int>(v));
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<facebook::react::EllipsizeMode>
|
||||
{
|
||||
size_t operator()(const facebook::react::EllipsizeMode& v) const
|
||||
{
|
||||
return hash<int>()(static_cast<int>(v));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
|
@ -31,3 +34,15 @@ enum class LayoutDirection {
|
|||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <>
|
||||
struct hash<facebook::react::LayoutDirection>
|
||||
{
|
||||
size_t operator()(const facebook::react::LayoutDirection& v) const
|
||||
{
|
||||
return hash<int>()(static_cast<int>(v));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
|
||||
#include <fabric/graphics/ColorComponents.h>
|
||||
|
@ -58,3 +59,15 @@ ColorComponents colorComponentsFromColor(SharedColor color);
|
|||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <>
|
||||
struct hash<facebook::react::SharedColor>
|
||||
{
|
||||
size_t operator()(const facebook::react::SharedColor& sharedColor) const
|
||||
{
|
||||
return hash<decltype(*sharedColor)>{}(*sharedColor);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue