gpt4 book ai didi

c++ - Boost assert.hpp 文件中的 P::************ 是什么意思?

转载 作者:IT老高 更新时间:2023-10-28 12:02:33 25 4
gpt4 key购买 nike

boost/mpl/assert.hpp ,我看到了这样的东西:

template<class Pred>
struct eval_assert {
typedef typename extract_assert_pred<Pred>::type P;
typedef typename P::type p_type;
typedef typename ::boost::mpl::if_c<p_type::value,
AUX778076_ASSERT_ARG(assert<false>),
failed ************ P::************
>::type type;
};

如果第一个************可以视为struct的指针失败,则P::********* *** 对我来说真的没有任何意义。这是标准的 C++ 吗?

最佳答案

这段代码的目的是帮助编译器产生“可见”的错误信息。

static_assert 之前的时代,编译大量模板代码很容易产生大约 100 行错误消息,即使是一个错误,其中 99% 的行通常都是无意义的。

10 指针技巧有助于指出实际错误,例如:

 BOOST_STATIC_ASSERT((std::is_same<T,U>));

使用 gcc 编译的 T=void*U=char* 会产生大约 10 条错误行,但您可以很容易地看到相关的:

error: no matching function for call to ‘assertion_failed(mpl_::failed************ std::is_same<void*, char*>::************)’

关于c++ - Boost assert.hpp 文件中的 P::************ 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27025929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com