check for existence of static member variable

  • Thread starter usenet only_tech_talk
  • Start date
U

usenet only_tech_talk

Hello,

I tested the code below on a boost::array<> which defines
static const size_type static_size = N;
and it fails. See http://www.boost.org/doc/libs/1_42_0/doc/html/boost/array.html

Am I getting the pointer signature wrong for a static mv? Note that a
similar test works for size() (see the code that is commented out).
Any suggestion would be appreciated. Thanks.

template<typename T>
struct has_static_size{
typedef typename T::size_type size_type;
typedef char yes;
typedef char (&no)[2];
typedef const size_type* sig;
// typedef size_type (const T::*sig)();

template<typename U,sig>
struct sfinae { };

template<typename U> static yes test(sfinae<U, &U::static_size>
*);
//template<typename U> static yes test(sfinae<U,&U::size> *);
template<typename U> static no test(...);

BOOST_STATIC_CONSTANT(
bool,
value = sizeof( test<T>(0) ) == sizeof(yes)
);

typedef boost::mpl::bool_<value> type;
};
 
U

usenet only_tech_talk

Hello,

I tested the code below on a boost::array<> which defines
  static const size_type static_size = N;
and it fails. Seehttp://www.boost.org/doc/libs/1_42_0/doc/html/boost/array.html

Am I getting the pointer signature wrong for a static mv? Note that a
similar test works for size() (see the code that is commented out).
Any suggestion would be appreciated. Thanks.

    template<typename T>
    struct has_static_size{
       typedef typename T::size_type size_type;
       typedef char yes;
       typedef char (&no)[2];
       typedef const size_type* sig;
//       typedef size_type (const T::*sig)();

       template<typename U,sig>
       struct sfinae { };

       template<typename U> static yes test(sfinae<U, &U::static_size>
*);
       //template<typename U> static yes test(sfinae<U,&U::size> *);
       template<typename U> static no test(...);

       BOOST_STATIC_CONSTANT(
                bool,
               value = sizeof( test<T>(0) ) == sizeof(yes)
        );

        typedef boost::mpl::bool_<value> type;
   };

PS: I use OSX 10.6 and gcc 4.2
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top