作者WangDaMing (王大明)
看板C_and_CPP
標題[問題] c++語法
時間Sun Jun 6 22:31:53 2021
開發平台(Platform): (Ex: Win10, Linux, ...)
Linux
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
GCC
問題(Question):
請問m4這個lamda初始化Cmp是什麼語法??
在書上看到這段code可是沒解釋這段的寫法,這個就我的理解,
好像也不是List initialization ?
可以不管前面兩個參數直接匹配到Cmp??
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
// g++ std-map.cpp -o a.out -std=c++11
#include <iostream>
#include <string>
#include <map>
using namespace std;
using Cmp = bool(*)(const int&,const int&);
int main() {
map<int,int,Cmp> m4{[](const int &a,const int &b){return a>b;}};
return 0;
}
感謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 27.242.38.14 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1622989915.A.E37.html
→ nh60211as: 上面網頁的第一個constructor,直接帶入comparator 06/06 22:37
→ WangDaMing: 沒想到沒有key/value,也可以建構...感謝 06/08 19:14