Skip to content

Instantly share code, notes, and snippets.

@pozdneev
Created May 5, 2021 20:03
Show Gist options
  • Save pozdneev/6309c767402ae2d6385b349e454384db to your computer and use it in GitHub Desktop.
Save pozdneev/6309c767402ae2d6385b349e454384db to your computer and use it in GitHub Desktop.
mem_fn: supplying template arguments
// g++ -std=c++14 -c mem_fn.cpp
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;
struct A {
int& getAttribute();
const int& getAttribute() const;
};
vector<int> foo(const vector<A>& as) {
vector<int> is;
transform(as.begin(), as.end(), back_inserter(is),
mem_fn<const int& () const>(&A::getAttribute));
return is;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment