Back on my crazy AutoArray thingy... (quoting important bits from there:
class AutoArray
{
void * buffer;
public:
//Creates a new empty AutoArray
AutoArray();
//std::auto_ptr copy semantics
AutoArray(AutoArray&); //Note it can't be const because the "other" reference
//is null'd on copy...
AutoArray& operator=(AutoArray);
~AutoArray();
//Nothrow swap
// Note: At the moment this method is not thread safe.
void Swap(AutoArray&);
};
)
Anyway, trying to implement the copy constructor. There's a piece of client code (not yet committed into bitbucket because it won't build) that looks like this:
AutoArray NtQuerySystemInformation(...) { ... };
AutoArray systemInfoBuffer = NtQuerySystemInformation(...);
This fails because the copy constructor takes a non-const
reference as an argument .... but I don't see how you could modify the copy constructor to take a const
reference, given that the source AutoArray
used in the assignment is modified (and therefore wouldn't be const
). You can't modify things to use pass by value of course, because it's the copy constructor and that'd be an infinite loop!
If I was using auto_ptr
, this would be valid:
std::auto_ptr NtQuerySystemInformation(...) { ... };
std::auto_ptr systemInfoBuffer = NtQuerySystemInformation(...);
How then, can a class with auto_ptr
's copy semantics be possible?
inline
in front of thestd::swap
specialization. – Anticipatebuffer
needs to be atomic. It needs to be aboost::/std::atomic<void*>
instead. Imagine someone calls swap while another thread just accesses it with some other method, you'd have a problem. (Again, swap will likely need a mutex, so you'd just mutex every method.) But just wanted to make sure you weren't going to try to protect one function and not any others. – LoferskiWindowsApi::AutoArray
class :) – Yousuf