c++11: what is its gc interface, and how to implement?

前端 未结 2 1704
星月不相逢
星月不相逢 2020-12-18 04:08

I was watching Bjarne Stroustrup\'s talk \"The Essence of C++\".

In 44:26 he mentioned \"C++11 specifies a GC Interface\".

May I ask what is the interface, a

2条回答
  •  一生所求
    2020-12-18 04:27

    In addition to the good answer by quantdev, which I've upvoted, I wanted to provide a little more information here (which would not fit in a comment).

    Here is a C++11 conforming program which demonstrates whether or not an implementation supports the GC interface:

    #include 
    #include 
    
    int
    main()
    {
    #ifdef __STDCPP_STRICT_POINTER_SAFETY__
        std::cout << __STDCPP_STRICT_POINTER_SAFETY__ << '\n';
    #endif
        switch (std::get_pointer_safety())
        {
        case std::pointer_safety::relaxed:
            std::cout << "relaxed\n";
            break;
        case std::pointer_safety::preferred:
            std::cout << "preferred\n";
            break;
        case std::pointer_safety::strict:
            std::cout << "strict\n";
            break;
        }
    }
    

    An output of:

    relaxed
    

    means that the implementation has a trivial implementation which does nothing at all.

    libc++ outputs:

    relaxed
    

    VS-2015 outputs:

    relaxed
    

    gcc 5.0 outputs:

    prog.cc: In function 'int main()':
    prog.cc:10:13: error: 'get_pointer_safety' is not a member of 'std'
        switch (std::get_pointer_safety())
                ^
    

提交回复
热议问题