std::atomic<> MSVC 中的运算符++
std::atomic<> operator++ in MSVC
来自MSDN:
Ty atomic<Ty>::operator++(int) volatile _NOEXCEPT;
Ty atomic<Ty>::operator++(int) _NOEXCEPT;
Ty atomic<Ty>::operator++() volatile _NOEXCEPT;
Ty atomic<Ty>::operator++() _NOEXCEPT;
The first two operators return the incremented value; the last two operators return the value before the increment.
但是,C++11 文档从这个运算符 as
定义了 returns
The value of the atomic variable after the modification. Formally, the result of incrementing/decrementing the value immediately preceding the effects of this function in the modification order of *this.
为什么 MSVC++ 编译器使用非标准定义?
这是 MSDN 上的文档错误。本次测试程序(LIVE):
#include <atomic>
#include <iostream>
template <typename T>
void foo(T&& t) {
std::cout << ++t << '\n';
std::cout << t++ << '\n';
std::cout << static_cast<int>(t) << '\n';
}
int main()
{
foo(0);
foo(std::atomic<int>{0});
}
正确输出:
1
1
2
1
1
2
使用 VS2013 编译时。
来自MSDN:
Ty atomic<Ty>::operator++(int) volatile _NOEXCEPT; Ty atomic<Ty>::operator++(int) _NOEXCEPT; Ty atomic<Ty>::operator++() volatile _NOEXCEPT; Ty atomic<Ty>::operator++() _NOEXCEPT;
The first two operators return the incremented value; the last two operators return the value before the increment.
但是,C++11 文档从这个运算符 as
定义了 returnsThe value of the atomic variable after the modification. Formally, the result of incrementing/decrementing the value immediately preceding the effects of this function in the modification order of *this.
为什么 MSVC++ 编译器使用非标准定义?
这是 MSDN 上的文档错误。本次测试程序(LIVE):
#include <atomic>
#include <iostream>
template <typename T>
void foo(T&& t) {
std::cout << ++t << '\n';
std::cout << t++ << '\n';
std::cout << static_cast<int>(t) << '\n';
}
int main()
{
foo(0);
foo(std::atomic<int>{0});
}
正确输出:
1 1 2 1 1 2
使用 VS2013 编译时。