Search code examples
c++c++11type-traits

‘is_trivially_copyable’ is not a member of ‘std’


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!


Solution

  • 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_trivially_copyable
    • is_trivially_constructible
    • is_trivially_default_constructible,
    • is_trivially_copy_constructible
    • is_trivially_move_constructible
    • is_trivially_assignable
    • is_trivially_default_assignable
    • is_trivially_copy_assignable
    • is_trivially_move_assignable

    That being said:

    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