What does P::************ mean in Boost assert.hpp file?

C++PointersBoost

C++ Problem Overview


In boost/mpl/assert.hpp, I saw something like this:

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;
};

If the first ************ can be treated as pointers of struct failed, the P::************ really doesn't make any sense to me. Is this standard C++?

C++ Solutions


Solution 1 - C++

The point of this code is to help the compiler produce "visible" error messages.

In pre static_assert era, compiling a template-heavy code could easily produce ~100 lines of error messages even for a single mistake, and 99% of those lines are often meaningless.

The 10 pointers trick is useful to point out the actual error, for example:

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

With T=void* and U=char* compiled with gcc produces ~10 error lines, but you can easily see the relevant one:

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

Solution 2 - C++

It's a pointer-to-pointer-to-...-member of type P, where the member is a data member of type pointer-to-pointer-to-...-failed.

In this case the goal is simply to cause compilation to fail by referring to a member of P with a very high degree of probability that it won't exist. In C++11 you'd just use static_assert instead, but of course Boost needs to be portable to pre-C++11 dialects.

Solution 3 - C++

F P::* is a "pointer to member of P of type F".

F P::** is a "pointer to pointer to member of P of type F".

More *s adds more "pointer to" in front.

In this case, F is failed ************, i.e., "pointer to pointer to ... pointer to failed".

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionstoneyanView Question on Stackoverflow
Solution 1 - C++sbabbiView Answer on Stackoverflow
Solution 2 - C++cdhowieView Answer on Stackoverflow
Solution 3 - C++T.C.View Answer on Stackoverflow