我有一個類型列表定義爲:使用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