[PATCH v2 1/2] c++, libstdc++: implement __is_pointer built-in trait
Jonathan Wakely
jwakely@redhat.com
Wed Jul 12 10:01:24 GMT 2023
On Mon, 10 Jul 2023 at 06:51, Ken Matsui via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> Hi,
>
> Here is the benchmark result for is_pointer:
>
> https://github.com/ken-matsui/gcc-benches/blob/main/is_pointer.md#sun-jul--9-103948-pm-pdt-2023
>
> Time: -62.1344%
> Peak Memory Usage: -52.4281%
> Total Memory Usage: -53.5889%
Wow!
Although maybe we could have improved our std::is_pointer_v anyway, like so:
template <typename _Tp>
inline constexpr bool is_pointer_v = false;
template <typename _Tp>
inline constexpr bool is_pointer_v<_Tp*> = true;
template <typename _Tp>
inline constexpr bool is_pointer_v<_Tp* const> = true;
template <typename _Tp>
inline constexpr bool is_pointer_v<_Tp* volatile> = true;
template <typename _Tp>
inline constexpr bool is_pointer_v<_Tp* const volatile> = true;
I'm not sure why I didn't already do that.
Could you please benchmark that? And if it is better than the current
impl using is_pointer<_Tp>::value then we should do this in the
library:
#if __has_builtin(__is_pointer)
template <typename _Tp>
inline constexpr bool is_pointer_v = __is_pointer(_Tp);
#else
template <typename _Tp>
inline constexpr bool is_pointer_v = false;
template <typename _Tp>
inline constexpr bool is_pointer_v<_Tp*> = true;
template <typename _Tp>
inline constexpr bool is_pointer_v<_Tp* const> = true;
template <typename _Tp>
inline constexpr bool is_pointer_v<_Tp* volatile> = true;
template <typename _Tp>
inline constexpr bool is_pointer_v<_Tp* const volatile> = true;
#endif
More information about the Gcc-patches
mailing list