facebookarchive / RakNet

RakNet is a cross platform, open source, C++ networking engine for game programmers.
Other
3.3k stars 1.02k forks source link

Templated BitStream::operator << should take a reference to a const value #52

Open SrTobi opened 9 years ago

SrTobi commented 9 years ago

The BitStream has a << operator which simply takes any argument and redirects it to BitStream::Write(...):

template <class templateType>
BitStream& operator<<(BitStream& out, templateType& c)
{
    out.Write(c);
    return out;
}

c (or the value referenced) however will never be changed, so that c should be const. Then the following code becomes valid:

RakString some_str()
{
    ...
}

BitStream bs;
bs << MessageID(0);
bs << some_str();