My gcc version is 4.8.3 20140624. I can use is_pod
, is_trivial
, is_standard_layout
, but fail when trying is_trivially_copyable
, is_constructible
and is_default_constructible
, maybe more. The error message is 'xxx' is not a member of 'std'
.
What's the problem here? Are they even supported by the current GCC? Thanks!
The diagnostic is not required, but std::atomic requires a trivially copyable type and std::string is not one.
A trivially copy constructible type is a type which can be trivially constructed from a value or reference of the same type. This includes scalar types, trivially copy constructible classes and arrays of such types.
As others mention, GCC versions < 5 do not support std::is_trivially_copyable
from the C++11 standard.
Here is a hack to somewhat work around this limitation:
// workaround missing "is_trivially_copyable" in g++ < 5.0
#if __GNUG__ && __GNUC__ < 5
#define IS_TRIVIALLY_COPYABLE(T) __has_trivial_copy(T)
#else
#define IS_TRIVIALLY_COPYABLE(T) std::is_trivially_copyable<T>::value
#endif
For common cases, this hack might be enough to get your code working. Beware, however, subtle differences between GCC's __has_trivial_copy
and std::is_trivially_copyable
. Suggestions for improvement welcome.
Some of them are not implemented. If we look at libstdc++'s c++11 status page:
Type properties are listed as partially implemented.
They list as missing:
is_constructible
and is_default_constructible
should be available. I can use them successfully in GCC 4.8.2.
#include <type_traits>
#include <iostream>
int main() {
std::cout << std::is_constructible<int>::value << "\n";
std::cout << std::is_default_constructible<int>::value << "\n";
}
[11:47am][wlynch@apple /tmp] /opt/gcc/4.8.2/bin/g++ -std=c++11 foo.cc
[11:47am][wlynch@apple /tmp] ./a.out
1
1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With