이미 다른 접근 방식으로 제출되었지만 숙제입니다. 나는 비주얼 스튜디오에서 다음지고있어 2008
error C2893: Failed to specialize function template 'void std::sort(_RanIt,_RanIt,_Pr)'
main.cpp
Database<> db;
db.loadDatabase();
bind1st(mem_fun(&my_class::f), this) 펑터를 for_each으로 전달하고 싶습니다. (the type I am looking for) meaningful_name = bind1st(mem_fun(&my_class::f), this);
for_each(v.begin(), v.end(), meaningful_name);
펑의
아래 코드를 참조하십시오. drive()은이고, drive은 porsche입니다. 그러나, drive()의 선언을 주석 처리하지 않으면, g ++는 매우 이상한 '드라이브'를 제공합니다.이 범위 오류에서 펑터를 만들려고 할 때 선언되지 않았습니다. 왜? #include <functional>
class car {
friend void drive
newtype에 의존하지 않고 에 (a, a)을 어떻게 만들 수 있습니까? instance Functor (a, a) where
fmap f (x, y) = (f x, f y)
그러나 그것을 표현하는 합법적 인 방법은 아니다 물론는 : Kind mis-match
The first argument of `Functor' should have k
Functor 스타일 술어 대신 정적 멤버 함수와 함께 템플릿 매개 변수를 사용할 때 성능상의 이점이 있습니까 ?? 예를 들어 는 펑터 스타일의 종류의 인터페이스는 일반적으로이 같은 것입니다 : 당신은 더 이런 일을 할 수 template <typename _Type, typename _Pred>
void sort (
RandomAccessIter
나는 제 I는 A와 B 파라미터 심지어 어떤 괄호없이 펑이 sort_ints에서 언급 된 오퍼레이터() (INT의 A, INT의 B)로 전달 됐는지 궁금에서 Wikipedia class compare_class {
public:
bool operator()(int A, int B) const {
return A < B;
나는 MyClass의 목록을 가지고 : struct MyClass {
bool is_old_result(int lifetime);
};
std::list<MyClass> results;
int lifetime = 50; // or something else
더 나은 ( C++ 설계 및 성능)는 제거 어떤 경우 : results.remove
난 그냥 "깊이에서 C 번호"를 통해 탐색하고 다음 코드 우연히 : 두 가지 기능을 추가하는 것은 수학에 의미가 있음을 Func<string> stringFunc =() => "";
Func<object> objectFunc =() => new object();
Func<object> combined = objectFunc + stringFunc;
나는 c.drive() 전화 run 원하는 : #include <functional>
using namespace std;
struct Car {
void drive() { }
};
template <typename Function>
void run(Function f) {
f();
}
int main() {
C