I'm trying to detect at compile time whether a class Foo
or Bar
has either the variable value
or member variable initValue()
.
struct Foo
{
static const int value;
static int initValue();
};
struct Bar
{
};
I've found several boost and boost MPL classes and utils such as BOOST_MPL_HAS_XXX_TRAIT_DEF
and valid_member_metafunction
that appear to do just this but am unsure which to use. I know it's possible to roll out my own detector but I'd rather not.
Found it. has_static_member_data
and has_static_member_function
from the Boost TTI library.
#include <boost/tti/has_static_member_data.hpp>
BOOST_TTI_HAS_STATIC_MEMBER_DATA( value ) // Generates class template has_static_member_data_value
...
has_static_member_data_value<Foo, int>::value; // returns true
has_static_member_data_value<Bar, int>::value; // returns false