How to deal with noexcept in Visual Studio

前端 未结 11 1700
一整个雨季
一整个雨季 2021-01-31 07:42

I\'m trying to create a custom exception that derives from std::exception and overrides what(). At first, I wrote it like this:

class U         


        
11条回答
  •  时光说笑
    2021-01-31 08:20

    use BOOST_NOEXCEPT in

    The boost config library was designed for compatibility issues like this. According to the doc:

    If BOOST_NO_CXX11_NOEXCEPT is defined (i.e. C++03 compliant compilers) these macros are defined as:

        #define BOOST_NOEXCEPT
        #define BOOST_NOEXCEPT_OR_NOTHROW throw()
        #define BOOST_NOEXCEPT_IF(Predicate)
        #define BOOST_NOEXCEPT_EXPR(Expression) false
    

    If BOOST_NO_CXX11_NOEXCEPT is not defined (i.e. C++11 compliant compilers) they are defined as:

        #define BOOST_NOEXCEPT noexcept
        #define BOOST_NOEXCEPT_OR_NOTHROW noexcept
        #define BOOST_NOEXCEPT_IF(Predicate) noexcept((Predicate))
        #define BOOST_NOEXCEPT_EXPR(Expression) noexcept((Expression))
    

    Many of the other answers here have a similar implementation but this library is cleaner, better tested, and will do the right thing when your compiler is upgraded. I recommend looking at the boost config library in general for other features, especially in this time of language flux and varying levels of support among compilers.

提交回复
热议问题