Skip to main content
gamedev.net
🔒 Locked

mutable data types (c++)

Started by bradbobak 3 replies 1.5k views
Original Post
bradbobak
bradbobak
Hi.. I currently am using a class that locks a mutex on data read and thus cannot declare itself as 'const' because the mutex writes.. would this be a good use of the 'mutable' operator??

class foo
{
  lock l; 
  int i;

 public:
  int get() // I would like to put 'const' here
  { 
   l.lock();
   int r = i;
   l.unlock();
   return (r); 
};
CTar
CTar
I would say that would be a good place to use mutable.
joanusdmentia
joanusdmentia
Yep. The mutex has no bearing on the internal state of your object, it's just there for synchronisation.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The nly verdict is vengeance; a vendett o
MaulingMonkey
MaulingMonkey
I jump on the boat, allready overcrowded, of people stating that mutable here would not be bad mojo.
Troll
Troll
To join the parade, it's examples like this one that lead to the decision to add mutable to C++.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.