Please help me understand why this is providing an issue; I want to determine the maximum number of elements without utilising any extra space.
Code:
#include <bits/stdc++.h>
using namespace std;
int main() {
cout<<*max_element({4,6,2,5});
}
Error:
error : prog.cpp: In function ‘int main()’:
prog.cpp:5:30: error: no matching function for call to ‘max_element(<brace-enclosed initializer list>)’
cout<<*max_element({4,6,2,5});
^
In file included from /usr/include/c++/5/algorithm:62:0,
from /usr/include/x86_64-linux-gnu/c++/5/bits/stdc++.h:64,
from prog.cpp:1:
/usr/include/c++/5/bits/stl_algo.h:5505:5: note: candidate: template<class _FIter> constexpr _FIter std::max_element(_FIter, _FIter)
max_element(_ForwardIterator __first, _ForwardIterator __last)
^
/usr/include/c++/5/bits/stl_algo.h:5505:5: note: template argument deduction/substitution failed:
prog.cpp:5:30: note: candidate expects 2 arguments, 1 provided
cout<<*max_element({4,6,2,5});
^
In file included from /usr/include/c++/5/algorithm:62:0,
from /usr/include/x86_64-linux-gnu/c++/5/bits/stdc++.h:64,
from prog.cpp:1:
/usr/include/c++/5/bits/stl_algo.h:5529:5: note: candidate: template<class _FIter, class _Compare> constexpr _FIter std::max_element(_FIter, _FIter, _Compare)
max_element(_ForwardIterator __first, _ForwardIterator __last,
^
/usr/include/c++/5/bits/stl_algo.h:5529:5: note: template argument deduction/substitution failed:
prog.cpp:5:30: note: candidate expects 3 arguments, 1 provided
cout<<*max_element({4,6,2,5});