According to cppreference.com a.m
is prvalue
the member of object expression, where m is a member enumerator or a non-static member function[2];
Does it mean for object expression ie a.m where m is a member of a of enumeration type, the value category of expression itself would be prvalue?
As per my following testing, it does not seem to be the case. What did I miss?
enum class Color : char {
Red = 'r'
};
struct Test {
Color c;
};
void func(Color&&) {
std::cout << "rvalue ref\n";
}
void func(Color&) {
std::cout << "lvalue ref\n";
}
int main()
{
Test t;
func(t.c);
return 0;
}
Output:
lvalue ref
So the 'enumerator' is the value of an enumeration not an object of the type of the enumeration: https://en.cppreference.com/w/cpp/language/enum
An enumeration is a distinct type whose value is restricted to a range of values, which may include several explicitly named constants ("enumerators").
Slightly edited to remove fluff, bolding mine
So the standard is referring to when you access a class enumerator like:
struct Test {
enum Colour {
Red
};
};
...
Test t;
t.Red; // <- This is a prvalue
Here is a live example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With