partitioning - Error with C++ array partition compilation -
i have problem when trying compile code:
#include <iostream> #include <functional> using namespace std; template <typename t> size_t partition(t arr[], size_t size, function<bool(t)> lambda) { int index = 0; for(int = 0; < size; i++) { if(fun(arr[i]) == true) { //jeśli element spełnia predykat zamien go z arr[index] ustaw index na 'i' int tmp = arr[index]; arr[index] = arr[i]; arr[i] = tmp; index = i; } else { //na początku gdy index = 0, powiększ if(index == 0) index = i; } } return index; } template <typename t> void printtable(t arr[], size_t size) { cout << "[ "; for(int = 0; < size; i++) { cout << arr[i] << " "; } cout << "] "; } template <typename t> bool less10(t a) { return < 10; } int main() { int arri[] = {1,20,3,50,6,7}; size_t sizi = sizeof(arri)/sizeof(arri[0]); printtable(arri, sizi); size_t fi = partition(arri,sizi, (function<bool(int)>)less10<int>); printtable(arri,sizi); cout << "index: " << fi << endl; cout << endl; double arrd[] = {1,20,3,50,6,7}; size_t sizd = sizeof(arrd)/sizeof(arrd[0]); printtable(arrd, sizd); function<bool(double)> lambda = [] (double x) -> bool {return x > 10;}; size_t fd = partition(arrd,sizd,lambda); printtable(arrd,sizd); cout << "index: " << fd << endl; }
here have error output:
6 c:\documents , settings\grzegorz\pulpit\funkcje.cpp `function' has not been declared 6 c:\documents , settings\grzegorz\pulpit\funkcje.cpp expected `,' or `...' before '<' token 6 c:\documents , settings\grzegorz\pulpit\funkcje.cpp iso c++ forbids declaration of `parameter' no type c:\documents , settings\grzegorz\pulpit\funkcje.cpp in function `int main()': 43 c:\documents , settings\grzegorz\pulpit\funkcje.cpp `function' undeclared (first use function) (each undeclared identifier reported once each function appears in.) 43 c:\documents , settings\grzegorz\pulpit\funkcje.cpp expected primary-expression before "bool" 43 c:\documents , settings\grzegorz\pulpit\funkcje.cpp expected `)' before "bool" 50 c:\documents , settings\grzegorz\pulpit\funkcje.cpp expected primary-expression before "bool" 50 c:\documents , settings\grzegorz\pulpit\funkcje.cpp expected `;' before "bool" 51 c:\documents , settings\grzegorz\pulpit\funkcje.cpp `lambda' undeclared (first use function)
Comments
Post a Comment