I was surprised that type decay is not well explained on SO or elsewhere, maybe I did not look for the correct terms, or maybe I do not understand everything correctly. My question is: what is it, how (why) did it get there, and what are its rules?
If you are wondering why I ask, below is a story about the decay of my sob ( not the topic of the question):
I recently struggled with some simple patterns, and I wanted to do something like this:
template <class FunObj>
double DoStuff(FunObj fob) // note that this returns double, not FunObj, as e.g. std::for_each() does
{ }
struct MyFunObj {
mutable size_t num_invoked;
MyFunObj()
:num_invoked(0)
{}
bool operator ()(double some_arg) const
{
++ num_invoked;
return sin(some_arg) < .5;
}
};
, , , . , ( , ), . (, , ):
MyFunObj fob;
DoStuff(fob);
MyFunObj &ref = fob;
DoStuff(ref);
DoStuff(static_cast<MyFunObj&>(fob));
, , , , . , / . , mutable.