Why are there free and member functions for comparison and swap operations?

The C ++ Standard Library has free and member functions for atomic comparison and swap operations.

As indicated by the free features :

These functions are defined in terms of the std :: atomic member functions:

  • obj-> compare_exchange_weak (* expected, desired)
  • obj-> compare_exchange_strong (* expected, desirable)
  • obj-> compare_exchange_weak (* expected, desired, succ, fail)
  • obj-> compare_exchange_strong (* expected, desired, succ, fail)

What is the reason for having free features? Wouldn't it be enough to have only member functions? Don't they do the same?

+6
source share
1 answer

Consistency with C operations stdatomic.h.

If you use free functions, then the same atom control code will work both in C and C ++, and only for typedef a conditional definition is required.

+6
source

All Articles