次のようなコードがあります。
#include <vector>
#include <utility>
int main()
{
std::vector<bool> vb{true, false};
std::swap(vb[0], vb[1]);
}
脇の正気についての議論vector<bool>、これはうまく機能していました:
- Mac用のクラン
- Visual Studio for Windows
- Linux 用 GCC
次に、Windows で Clang を使用してビルドしようとしたところ、次のエラー (要約) が表示されました。
error: no matching function for call to 'swap'
std::swap(vb[0], vb[1]);
^~~~~~~~~
note: candidate function [with _Ty = std::_Vb_reference<std::_Wrap_alloc<std::allocator<unsigned int> > >, $1 = void] not viable: expects an l-value for 1st argument
inline void swap(_Ty& _Left, _Ty& _Right) _NOEXCEPT_COND(is_nothrow_move_constructible_v<_Ty>&&
実装によって結果が異なることに驚いています。
Windows の Clang で動作しないのはなぜですか?