MyTinySTL icon indicating copy to clipboard operation
MyTinySTL copied to clipboard

Fix `address_of` for overloaded `operator&`

Open frederick-vs-ja opened this issue 1 year ago • 0 comments

Fixes #133.

策略:

  • 如果编译器支持 __builtin_addressof 则使用;
  • 否则,使用 SFINAE
    • 对函数使用内建 operator&
    • 对对象使用 reinterpret_cast 到字节类型再取地址的策略(与 constexpr 不兼容)。

为了避免 addressof<const int>(42) 之类取临时对象的代码通过编译,对右值提供被删除的重载(实现 LWG2598)。

frederick-vs-ja avatar Oct 10 '23 16:10 frederick-vs-ja