Skip to content

Instantly share code, notes, and snippets.

@pozdneev
Created May 5, 2021 20:01
Show Gist options
  • Save pozdneev/a55fc2328ecd534a6694ab31e9a51883 to your computer and use it in GitHub Desktop.
Save pozdneev/a55fc2328ecd534a6694ab31e9a51883 to your computer and use it in GitHub Desktop.
mem_fn: no match for call
// g++ -std=c++14 -c mem_fn.cpp
//
// /usr/include/c++/7/bits/stl_algo.h:4306:24:
// error: no match for call to ‘(std::_Mem_fn<int& (A::*)()>) (const A&)’
//
// /usr/include/c++/7/functional:174:27:
// error: no matching function for call to ‘__invoke(int& (A::* const&)(), const A&)’
//
// /usr/include/c++/7/bits/invoke.h:89:5:
// error: no type named ‘type’ in ‘struct std::__invoke_result<int& (A::* const&)(), const A&>’
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;
struct A {
int& getAttribute();
};
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