От: | regnar | ||
Дата: | 16.06.15 23:20 | ||
Оценка: | -1 |
#include <functional>
#include <algorithm>
#include <vector>
int main()
{
std::vector<int> data;
std::function<bool(int, int)> cmp = [](int a, int b) { return a < b; };
std::sort(data.begin(), data.end(), cmp);
return 0;
}
От: | watchyourinfo | ||
Дата: | 16.06.15 23:26 | ||
Оценка: |
От: | netch80 | http://netch80.dreamwidth.org/ | |
Дата: | 17.06.15 06:24 | ||
Оценка: | 4 (2) |
$ g++5 -Wl,-rpath=/usr/local/lib/gcc5 regnar.cc -std=c++11
$ ./a.out
$
$ g++5 -v
Using built-in specs.
COLLECT_GCC=g++5
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc5/gcc/x86_64-portbld-freebsd9.3/5.1.0/lto-wrapper
Target: x86_64-portbld-freebsd9.3
Configured with: ./../gcc-5.1.0/configure --with-build-config=bootstrap-debug --disable-nls --enable-gnu-indirect-function --libdir=/usr/local/lib/gcc5 --libexecdir=/usr/local/libexec/gcc5 --program-suffix=5 --with-as=/usr/local/bin/as --with-gmp=/usr/local --with-gxx-include-dir=/usr/local/lib/gcc5/include/c++/ --with-ld=/usr/local/bin/ld --with-libiconv-prefix=/usr/local --with-pkgversion='FreeBSD Ports Collection' --with-system-zlib --disable-libgcj --enable-languages=c,c++,objc,fortran --prefix=/usr/local --localstatedir=/var --mandir=/usr/local/man --infodir=/usr/local/info/gcc5 --build=x86_64-portbld-freebsd9.3
Thread model: posix
gcc version 5.1.0 (FreeBSD Ports Collection)
От: | Ops | ||
Дата: | 17.06.15 06:27 | ||
Оценка: | +1 |
От: | Nuzhny | https://github.com/Nuzhny007 | |
Дата: | 17.06.15 09:55 | ||
Оценка: | +1 |
От: | andyp | ||
Дата: | 17.06.15 10:16 | ||
Оценка: | 1 (1) |
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
int main()
{
std::vector<int> data {5,4,3,2,1};
std::function<bool(int, int)> cmp = [](int a, int b) { return a < b; };
std::sort(data.begin(), data.end(), cmp);
for (auto a : data)
std::cout << a << std::endl;
return 0;
}
Много букв | |
| |
От: | regnar | ||
Дата: | 17.06.15 10:30 | ||
Оценка: |
Выхлоп | |
In file included from /usr/local/include/c++/5.1.0/bits/stl_algobase.h:71:0, from /usr/local/include/c++/5.1.0/bits/char_traits.h:39, from /usr/local/include/c++/5.1.0/string:40, from /usr/local/include/c++/5.1.0/stdexcept:39, from /usr/local/include/c++/5.1.0/array:38, from /usr/local/include/c++/5.1.0/tuple:39, from /usr/local/include/c++/5.1.0/functional:55, from test.cpp:1: /usr/local/include/c++/5.1.0/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterator2) [with _Iterator1 = int; _Iterator2 = int; _Compare = std::function<bool(int, int)>]': /usr/local/include/c++/5.1.0/functional:1982:6: required by substitution of 'template<class _Res, class ... _ArgTypes> template<class _Functor> using _Invoke = decltype (std::__callable_functor(declval<_Functor&>())((declval<_ArgTypes>)()...)) [with _Functor = __gnu_cxx::__ops::_Iter_comp_iter<std::function<bool(int, int)> >; _Res = bool; _ArgTypes = {int, int}]' /usr/local/include/c++/5.1.0/functional:1992:56: required by substitution of 'template<class _Res, class ... _ArgTypes> template<class _Functor> using _Callable = std::__and_<std::function<_Res(_ArgTypes ...)>::_NotSelf<_Functor>, std::__check_func_return_type<std::function<_Res(_ArgTypes ...)>::_Invoke<_Functor>, _Res> > [with _Functor = __gnu_cxx::__ops::_Iter_comp_iter<std::function<bool(int, int)> >; _Res = bool; _ArgTypes = {int, int}]' /usr/local/include/c++/5.1.0/functional:2057:9: required by substitution of 'template<class _Functor, class> std::function<_Res(_ArgTypes ...)>::function(_Functor) [with _Functor = __gnu_cxx::__ops::_Iter_comp_iter<std::function<bool(int, int)> >; <template-parameter-1-2> = <missing>]' /usr/local/include/c++/5.1.0/bits/predefined_ops.h:130:46: required from 'constexpr __gnu_cxx::__ops::_Iter_comp_iter<_Compare> __gnu_cxx::__ops::__iter_comp_iter(_Compare) [with _Compare = std::function<bool(int, int)>]' /usr/local/include/c++/5.1.0/bits/stl_algo.h:4729:70: required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _Compare = std::function<bool(int, int)>]' test.cpp:9:41: required from here /usr/local/include/c++/5.1.0/bits/predefined_ops.h:123:31: error: invalid type argument of unary '*' (have 'int') { return bool(_M_comp(*__it1, *__it2)); } ^ /usr/local/include/c++/5.1.0/bits/predefined_ops.h:123:39: error: invalid type argument of unary '*' (have 'int') { return bool(_M_comp(*__it1, *__it2)); } | |
От: | netch80 | http://netch80.dreamwidth.org/ | |
Дата: | 19.06.15 08:20 | ||
Оценка: |
От: | regnar | ||
Дата: | 19.06.15 21:45 | ||
Оценка: |