The C++ Standard Library has both free functions and member functions for atomic compare and swap operations.
As noted for free functions:
These functions are defined in terms of member functions of std::atomic:
- obj->compare_exchange_weak(*expected, desired)
- obj->compare_exchange_strong(*expected, desired)
- obj->compare_exchange_weak(*expected, desired, succ, fail)
- obj->compare_exchange_strong(*expected, desired, succ, fail)
What is the reason for having free functions? Wouldn't it be enough to have member functions only? Don't they do the same thing?