Could anybody explain what this code does?
struct EnumClass
{
template <typename T>
std::size_t operator()(T t) const
{
return static_cast<std::size_t>(t);
}
};
Could anybody explain what this code does?
struct EnumClass
{
template <typename T>
std::size_t operator()(T t) const
{
return static_cast<std::size_t>(t);
}
};
It defines the operator ()
for any object of type EnumClass
, taking one argument of any type. The operator evaluates to that argument, cast to type size_t
.
EnumClass e;
e(1); // evaluates to (size_t)1
This is borderline nonsense, of course. (It might make sense in some other context, but stand-alone and as-is, it doesn't -- you don't need an EnumClass
object to cast something to size_t
.)