[問題] 用boost lambda 代替stl set的functor
假設我有如下Class
內部存放一組bitset
template <unsigned int T>
class Unit
{
public:
Unit(int n):this->code_(n){}
int value(){ return (int)this->code_->to_ulong();}
private:
bitset<T> code_;
};
而在main裡我先用shared_ptr將Unit包起來,
再用stl::set來存放他,確保Unit會依照其直排序,
並另外自己寫一個functor傳進去當比較函數。
//comparator of Unit class
template <unsigned int T>
struct compare
{
bool operator()(const shared_ptr<Unit<T> >& a, const shared_ptr<Unit<T> >& b)
{
return a->value() < b->value();
}
};
int main()
{
set<shared_ptr<Unit<5> >, compare<5> > myset;
}
現在想請問一下,若是我不想自己額外再去寫一個compare的functor
而想直接利用boost lambda來替換掉compare<5>,該怎麼下手才好-_-
試過用bost::bind(&shared_ptr<Unit<5> >::get,_1)這樣的方向去組裝
但仍然會報錯說
main.cpp: error: Semantic Issue:
Template argument for template type parameter must be a type
試一個晚上試不出來,
謝謝!
--
※ 發信站 :批踢踢實業坊(ptt.cc)
◆ From: 111.250.64.140
※ 編輯: GreatShot 來自: 111.250.64.140 (10/14 01:48)
→
10/14 03:18, , 1F
10/14 03:18, 1F
→
10/14 03:18, , 2F
10/14 03:18, 2F
→
10/14 03:19, , 3F
10/14 03:19, 3F
因為LLVM還不支援(冏)
→
10/14 03:20, , 4F
10/14 03:20, 4F
這裡我不太明白
您的意思是指functor的部分改用weak_ptr
還是說set內存放weak_ptr呢
不知優點為何?
→
10/14 03:23, , 5F
10/14 03:23, 5F
→
10/14 03:23, , 6F
10/14 03:23, 6F
→
10/14 03:29, , 7F
10/14 03:29, 7F
Useful information!Thx!
→
10/14 21:30, , 8F
10/14 21:30, 8F
→
10/14 21:37, , 9F
10/14 21:37, 9F
我放棄了,乖乖自己寫comparator-_-
※ 編輯: GreatShot 來自: 111.250.64.140 (10/15 02:43)
→
10/15 03:04, , 10F
10/15 03:04, 10F
→
10/15 03:04, , 11F
10/15 03:04, 11F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章