C ++ std :: atomic <bool> :: fetch_or not implemented?
With this code excerpt:
class myclass { volatile std::atomic<bool> flag; public: myclass(): flag(false) {} bool get_flag() { return flag; } bool try_set() { return !flag.fetch_or(flag, true); } void reset() { flag = false; } }; I get this compilation error:
error: 'volatile struct std::atomic<bool>' has no member named 'fetch_or' return !flag.fetch_or(flag, true); It compiles if, however, I change the template parameter to int :
class myclass { volatile std::atomic<int> flag; public: myclass(): flag(0) {} bool get_flag() { return flag; } bool try_set() { return !flag.fetch_or(flag, true); } void reset() { flag = 0; } }; The atomic link states that the “full specialization of atomic<bool> ” is considered “non-specialized”, which I consider to be a source of problems. Therefore, my doubts:
- How can one "qualify full specialization" as non-specialized?
- Can I run into any complicated traps using the
intflag template parameter instead ofboolwhen callingflag.fetch_or()?
I am using gcc 5.1.0 and compiling with -std=c++14 .
C ++ 11 N3337 draft does not require this method for bool .
29.5 "Atomic types"
template <class T> struct atomic { [...] } template <> struct atomic<integral> { [...] integral fetch_or(integral , memory_order = memory_order_seq_cst) noexcept; [...] } 29.5 / 1:
The semantics of operations on atomic specializations are defined in 29.6.
29.6.3 / 2 "Arithmetic operations on atomic types":
In the declarations of these functions and specialized function templates, the name integral refers to the integral type, and the name atomic integral refers to either the atomic or the named base class for the integral from table 145 or from table 146.
and table 145 does not contain bool .
Thus, this method will have only the integral (without bool ) specialization struct .
This is a bit confusing because in the rest of the standard "integral types" include bool, 3.9.1 / 7 "Basic types":
The types are bool, char, char16_t, char32_t, wchar_t, and signed and unsigned integer types are called integer types. A synonym for the integral type is the integer type.