C++ Boost:API在1.46.1和1.58.0之间变化?

C++ Boost:API在1.46.1和1.58.0之间变化?,c++,api,boost,compatibility,boost-exception,C++,Api,Boost,Compatibility,Boost Exception,我的应用程序在Boost版本1.46.1上。 我想在Boost 1.58.0版上移植我的应用程序。 然而,我面临着一些问题 我注意到Boost1.58的boost::exception_ptr实现与1.46.1有所不同。在1.46.1中,boost::exception_ptr作为共享指针实现: typedef shared_ptr<exception_detail::clone_base const> exception_ptr; typedef共享\u ptr异常\u ptr

我的应用程序在Boost版本1.46.1上。 我想在Boost 1.58.0版上移植我的应用程序。 然而,我面临着一些问题

我注意到Boost1.58的
boost::exception_ptr
实现与1.46.1有所不同。在1.46.1中,
boost::exception_ptr
作为共享指针实现:

typedef shared_ptr<exception_detail::clone_base const> exception_ptr; 
typedef共享\u ptr异常\u ptr;
在1.58中,所有实现都封装在一个类中

class exception_ptr {
    typedef boost::shared_ptr<exception_detail::clone_base const> impl;
    impl ptr_;
    friend void rethrow_exception(exception_ptr const &);
    typedef exception_detail::clone_base const *(impl::*unspecified_bool_type)() const;

public:
    exception_ptr() {}
    explicit exception_ptr(impl const &ptr) : ptr_(ptr) {}
    bool operator==(exception_ptr const &other) const { return ptr_ == other.ptr_; }
    bool operator!=(exception_ptr const &other) const { return ptr_ != other.ptr_; }
    operator unspecified_bool_type() const { return ptr_ ? &impl::get : 0; }
};
类异常\u ptr{
typedef boost::shared_ptr impl;
impl-ptr;
友元无效重试异常(异常常量&);
typedef异常详细信息::克隆基本常量*(impl::*未指定类型)()常量;
公众:
异常_ptr(){}
显式异常ptr(impl const&ptr):ptr(ptr){
布尔运算符==(异常\u ptr const&other)const{return ptr\u==other.ptr\u;}
布尔运算符!=(异常\u ptr const&other)const{return ptr\u!=other.ptr\u;}
运算符未指定的\u bool\u type()常量{return ptr\u?&impl::get:0;}
};
由于这些更改,我的代码正在中断…:(


boost::exception\u ptr ExceptionHelper::GetExceptionPtr(MyExceptionPtr\u t exception){
boost::异常\u ptr结果=
boost::dynamic_pointer_cast(异常);//这是生成错误
返回结果;
}

MyExceptionPtr\u t ExceptionHelper::TryGetMyExceptionPtr(boost::exception\u ptr exception){
MyExceptionPtr\t结果;
boost::共享\u ptr constPtr=
boost::dynamic_pointer_cast(异常);//这是生成错误。
if(constPtr){
结果=boost::const\u指针\u cast(constPtr);
}
返回结果;
}

std::string ExceptionHelper::GetThrowFilename(const boost::exception\u ptr exception){
std::字符串结果;
如果(例外){
if(boost::get_error_info(*exception))//这是生成错误。
{
结果=*boost::获取错误信息(*异常);
}
}
返回结果;
}
你能不能建议我,如何修复上面的错误


谢谢

boost::exception_ptr
是默认的可构造、可复制、可分配和相等比较的。这些操作都不允许您提取捕获的异常本身。没有在类本身上指定其他操作。这没有从1.46.1更改为1.58.0;唯一的区别是实现选项已更改,因此很难意外使用不属于指定接口的
boost::exception_ptr
功能(就像您的代码那样)

唯一可能的其他操作是:

template <class T>
exception_ptr copy_exception( T const & e );    

exception_ptr current_exception();    

void rethrow_exception( exception_ptr const & ep );

我不知道MyExceptionPtr\u t的作用是什么。它看起来可以被
boost::exception\u ptr
取代(因此转换功能可能变得不必要),但如果没有所有的代码,我很难说清楚。

boost::exception_ptr是默认的可构造、可复制、可分配和相等可比的。所有这些操作都不允许您提取捕获的异常本身。没有在类本身上指定其他操作。这与1.46没有变化。1到1.58.0;唯一的区别是实现已更改,因此很难意外使用不属于指定接口的
boost::exception_ptr
功能(就像您的代码那样)

唯一可能的其他操作是:

template <class T>
exception_ptr copy_exception( T const & e );    

exception_ptr current_exception();    

void rethrow_exception( exception_ptr const & ep );

我不知道MyExceptionPtr\u t的作用是什么。它看起来可以被
boost::exception\u ptr
取代(因此转换功能可能变得不必要),但如果没有所有的代码,我很难说清楚。

在这段代码中,
MyExceptionPtr\t
的目的是什么,为什么不能用
boost::exception\ptr
替换它?这是我的自定义异常类,我的所有异常都应该由此派生。typedef boost::shared\ptr MyExceptionPtr\t;和类MyException:公共虚拟std::exception,公共虚拟boost::exception{--};在这段代码中,
MyExceptionPtr\u t
的目的是什么,为什么不能用
boost::exception\u ptr
替换它?这是我的自定义异常类,我的所有异常都应该由此派生。typedef boost::shared_ptr MyExceptionPtr\t;和类MyException:public virtual std::exception,public virtuall boost::exception{--};MyException是我的自定义异常类,我的所有异常都应该从此类派生。typedef boost::sharedptrmyexceptionptr_t;和类MyException:public virtual std::exception,public virtual boost::exception{public:explicit MyException(const std::string&what);virtual~MyException()throw(){}virtual const char*what()const throw();…..///返回boost::diagnostic_information(*this)virtual std::string diagnostic_information()const;-----------};MyException是我的自定义异常类,我的所有异常都应该从此类派生。typedef boost::shared_ptr MyExceptionPtr_t;和类MyException:public virtual std::Exception,public virtual boost::Exception{public:explicit MyException(const std::string&what);virtual~MyException()throw(){}virtual const char*what()const throw();…..///返回boost::diagnostic_information(*this)virtual std::string diagnostic_information()const;-----------};
std::string ExceptionHelper::GetThrowFilename(const boost::exception_ptr exception) {
    std::string result;
    if (exception) {
        if (boost::get_error_info<boost::throw_file>(*exception)) // This is giving build error.
        {
            result = *boost::get_error_info<boost::throw_file>(*exception);
        }
    }
    return result;
}
template <class T>
exception_ptr copy_exception( T const & e );    

exception_ptr current_exception();    

void rethrow_exception( exception_ptr const & ep );
std::string ExceptionHelper::GetThrowFilename(
    const boost::exception_ptr exception)
{
    std::string result;
    if (!exception) return result;
    try {
        boost::rethrow_exception(exception);
    }
    catch (boost::exception const &e) {
        boost::throw_file::value_type const *throw_file_data =
            boost::get_error_info<boost::throw_file>(e)
        if (throw_file_data) {
            result = *throw_file_data;
        }
    }
    return result;
}