Re: [問題] 利用 boost 的 Lambda 取代 C++0x:Lam …

看板C_and_CPP (C/C++)作者 ( )時間15年前 (2010/07/17 07:04), 編輯推噓2(200)
留言2則, 2人參與, 最新討論串2/2 (看更多)
※ 引述《spider391 (小乖)》之銘言: : #include <iostream> : #include <string> : #include <algorithm> : #include <vector> : #include <iterator> : #include <boost/lambda/lambda.hpp> #include <boost/lambda/bind.hpp> : using namespace std; using namespace boost::lambda; : int main(int argc, char** argv) { : vector<string> v; : v.push_back("What"); : v.push_back("ever"); : v.push_back("you"); : v.push_back("want"); : v.push_back("to"); : v.push_back("be"); sort(v.begin(), v.end(), bind(&string::size, _1) < bind(&string::size, _2)); : } bind 在這種場合的用法: bind(成員函式指標, 物件參考或物件指標, 不定參數) 推文很難改你的 code 所以用回的。 -- Ling-hua Tseng (uranus@tinlans.org) Department of Computer Science, National Tsing-Hua University Interesting: C++, Compiler, PL/PD, OS, VM, Large-scale software design Researching: Software pipelining for VLIW architectures Homepage: http://www.tinlans.org -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.160.104.245

07/17 09:51, , 1F
感謝,我之前一直試 bind 但是還不太了解它的使用方式^^
07/17 09:51, 1F

07/17 10:00, , 2F
好神奇 ( ̄▽ ̄#)﹏﹏
07/17 10:00, 2F
文章代碼(AID): #1CGEM1an (C_and_CPP)
文章代碼(AID): #1CGEM1an (C_and_CPP)