Is it possible to have a library implementation of is_trivially_constructible without relying on compiler builtins?
Asked Answered
E

1

6

I'm using gcc-4.9 which does not have the is_trivially_constructible type trait. Looking into the libstdc++ source code (type_traits), this depends on __is_trivially_constructible which is implemented in the compiler itself.

I was wondering if it was possible to implement this trait as a library rather than relying on compiler such that I can use this in my project which is stuck using gcc-4.9.

Erivan answered 18/4, 2018 at 13:42 Comment(5)
I don't think so. E.g. in the llvm implementation, the placeholder is_scalar is used which rather seems like a first approximation.Ferrer
For the record, MSVC (2015) also uses an intrinsic.Casaubon
@Ferrer LLVM also uses an intrinsic: github.com/llvm-mirror/libcxx/blob/master/include/…Dissymmetry
@Dissymmetry Yes, and in case it's not available, it will fall back on something that is actually wrong, indicating that if it was possible, the writers of libc++ would've done it.Ferrer
@Jodocus, I was also looking if there is some approximate implementation. That way some of the types will benefit.Erivan
S
6

No, it's not possible (otherwise we probably would have already done it in libstdc++!)

We had to wait for the new compiler builtin to be implemented.

Using is_scalar is a conservative approximation, but is obviously wrong for trivially constructible class types.

Sergias answered 18/10, 2018 at 16:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.