我有一个类型列表定义为:使用boost :: MPL ::拉姆达从升压删除类型:: MPL ::基于静态常量成员变量列表
typedef boost::mpl::list<Apple, Pear, Brick> OriginalList;
我想创建第二个列表不包含任何结果,即从第一个列表形成的结果列表将包含单个类型的Brick。果是通过:所述类型中的定义的静态常量变量,e.g
struct Apple
{
static const bool IsFruit = true;
};
我目前有涉及创建的元函数的类,并使用boost::mpl::remove_if
溶液识别。我相信我应该能够通过使用boost :: mpl :: lambda来取消对单独的RemoveFruit
结构的需求,从而使其更加优雅。有关如何做到这一点的任何建议?
的完整代码,因为它目前为:
include <boost/static_assert.hpp>
#include <boost/mpl/list.hpp>
#include <boost/mpl/remove_if.hpp>
#include <boost/mpl/size.hpp>
#include <iostream>
struct Apple
{
static const bool IsFruit = true;
};
struct Pear
{
static const bool IsFruit = true;
};
struct Brick
{
static const bool IsFruit = false;
};
typedef boost::mpl::list<Apple, Pear, Brick> OriginalList;
BOOST_STATIC_ASSERT(boost::mpl::size<OriginalList>::type::value == 3);
// This is what I would like to get rid of:
struct RemoveFruit
{
template <typename T>
struct apply
{
typedef boost::mpl::bool_<T::IsFruit> type;
};
};
// Assuming I can embed some predicate directly in here?
typedef boost::mpl::remove_if<
OriginalList,
RemoveFruit
>::type NoFruitList;
BOOST_STATIC_ASSERT(boost::mpl::size<NoFruitList>::type::value == 1);
int main()
{
std::cout << "There are " << boost::mpl::size<OriginalList>::type::value << " items in the original list\n";
std::cout << "There are " << boost::mpl::size<NoFruitList>::type::value << " items in the no fruit list\n";
return 0;
}
希望我们能有一个元模板,调试器。 :-D – stinky472 2010-06-28 23:26:56