8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C++11: state-lessな(一切のキャプチャをしない)ラムダ式は関数ポインタに暗黙変換できる

Posted at
#include <iostream>
#include <vector>
#include <cstdlib> // qsort

using namespace std;

int main() {
  vector<int> v { 8, 6, 4 ,2 ,0, 9, 7, 5, 3, 1 };
  // qsortの第4引数(比較関数へのポインタ)に state-less lambda を与える
  qsort(&v[0], v.size(), sizeof(int),
        [](const void* x, const void* y) {
          return *static_cast<const int*>(x) - *static_cast<const int*>(y);
        });
  for ( int item : v ) { cout << item << ' '; }
  cout << endl;
}
8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?