Boost logo

Boost :

Subject: Re: [boost] BOOST_STATIC_CONSTANT
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2017-08-17 00:19:49


On 17/08/2017 11:22, Vladimir Batov wrote:
> There is something seemingly basic that puzzles me greatly. I am hoping
> people might clarify something I totally fail to understand.
>
> I've been using BOOST_STATIC_CONSTANT for ages (with GCC). Now I have
> something seemingly non-controversial:
>
> template<typename user_type>
> struct impl_ptr
> {
> using yes_type = boost::type_traits::yes_type;
> using no_type = boost::type_traits::no_type;
> using ptr_type = typename std::remove_const<user_type>::type*;
>
> template<typename Y>
> static yes_type test (Y*, typename Y::impl_ptr_type* =nullptr);
> static no_type test (...);
>
> BOOST_STATIC_CONSTANT(bool, value = (1 ==
> sizeof(test(ptr_type(nullptr)))));
> };
>
> When compiled with gcc-.5.4.0, both lines below pass:
>
> BOOST_TEST(true == boost::impl_ptr<Shared>::value);
> BOOST_TEST(true == boost::impl_ptr<Shared const>::value);
>
> The only difference between them is "const". However, when I compile
> with clang-4.0, the second (const) line passes. However, the first one
> fails! I refuse to believe it's a clang glitch. It must be me doing
> something really stupid. Help?!

I can't answer this specific question, but since you're targeting C++11
anyway, shouldn't you be using std:: type traits?

So, something like:

template <typename T>
class has_impl_ptr_type
{
     template <typename T1>
     static typename T1::impl_ptr_type test(int);
     template <typename>
     static void test(...);
public:
     enum { value = !std::is_void<decltype(test<T>(0))>::value };
};


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk