Created
May 5, 2021 19:43
-
-
Save pozdneev/ea5c3f1b7481127bbcf7b739aa582fbb to your computer and use it in GitHub Desktop.
mem_fn: const-method only
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// g++ -std=c++14 -c mem_fn.cpp | |
#include <vector> | |
#include <functional> | |
#include <algorithm> | |
using namespace std; | |
struct A { | |
const int& getAttribute() const; | |
}; | |
vector<int> foo(const vector<A>& as) { | |
vector<int> is; | |
transform(as.begin(), as.end(), back_inserter(is), mem_fn(&A::getAttribute)); | |
return is; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment