我正在尝试将元函数专门用于具有函数指针作为其参数之一的类型。代码编译得很好,但它根本不匹配类型。
#include <iostream>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/identity.hpp>
template < typename CONT, typename NAME, typename TYPE, TYPE (CONT::*getter)() const, void (CONT::*setter)(TYPE const&) >
struct metafield_fun {};
struct test_field {};
struct test
{
int testing() const { return 5; }
void testing(int const&) {}
};
template < typename T >
struct field_writable : boost::mpl::identity<T> {};
template < typename CONT, typename NAME, typename TYPE, TYPE (CONT::*getter)() const >
struct field_writable< metafield_fun<CONT,NAME,TYPE,getter,0> > : boost::mpl::false_
{};
typedef metafield_fun<test, test_field, int, &test::testing, 0> unwritable;
int main()
{
std::cout << typeid(field_writable<unwritable>::type).name() << std::endl;
std::cin.get();
}
输出始终是传入的类型,绝不是 bool_。