[問題] c++語法

作者: WangDaMing (王大明)   2021-06-06 22:31:53
開發平台(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;
}
感謝
作者: nh60211as   2021-06-06 22:37:00
https://en.cppreference.com/w/cpp/container/map/map上面網頁的第一個constructor,直接帶入comparator
作者: WangDaMing (王大明)   2021-06-08 19:14:00
沒想到沒有key/value,也可以建構...感謝

Links booklink

Contact Us: admin [ a t ] ucptt.com