Vector aus Pairs mit numerical_limits
-
Hallo,
ich habe folgenden Code
#include <vector> #include <utility> #include <limits> using namespace std; int main(int argc, char **args) { int dim = 4; // funktioniert nicht, da will ich hin // vector<pair<double, double>> c1(dim, // make_pair(numeric_limits<double>::max, // numeric_limits<double>::lowest)); vector<pair<double, double>> c2(dim, make_pair(0.5, 1.5)); // (1) funktioniert vector<pair<double, double>> c3(dim, make_pair(numeric_limits<double>::max, 1.5)); // (2) funktioniert nicht return 0; }(1) funktioniert mit g++ und clang++ -std=c++11, warum aber nicht (2)? numeric_limits<T>::max gibt T zurück, hier also double. Aus meiner Sicht, sollte (2) damit von den Typen her das gleiche wie (1) sein.
Danke,
Florian
Fehlerausgaben:
% clang++ --std=c++11 test.cpp test.cpp:20:32: error: no matching constructor for initialization of 'vector<pair<double, double> >' vector<pair<double, double>> c3(dim, make_pair(numeric_limits<double>::max, 1.5)); //funktioniert nicht ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/stl_vector.h:277:7: note: candidate constructor not viable: no known conversion from 'pair<typename __decay_and_strip<double (&)()>::__type, typename __decay_and_strip<double>::__type>' to 'const allocator_type' (aka 'const std::allocator<std::pair<double, double> >') for 2nd argument vector(size_type __n, const allocator_type& __a = allocator_type()) ^ /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/stl_vector.h:289:7: note: candidate constructor not viable: no known conversion from 'pair<typename __decay_and_strip<double (&)()>::__type, [...]>' to 'const pair<double, [...]>' for 2nd argument vector(size_type __n, const value_type& __value, ^ /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/stl_vector.h:339:7: note: candidate constructor not viable: no known conversion from 'int' to 'const std::vector<std::pair<double, double>, std::allocator<std::pair<double, double> > >' for 1st argument vector(const vector& __x, const allocator_type& __a) ^ /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/stl_vector.h:348:7: note: candidate constructor not viable: no known conversion from 'int' to 'std::vector<std::pair<double, double>, std::allocator<std::pair<double, double> > >' for 1st argument vector(vector&& __rv, const allocator_type& __m) ^ /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/stl_vector.h:373:7: note: candidate constructor not viable: no known conversion from 'int' to 'initializer_list<value_type>' for 1st argument vector(initializer_list<value_type> __l, ^ /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/stl_vector.h:401:9: note: candidate template ignored: deduced conflicting types for parameter '_InputIterator' ('int' vs. 'std::pair<double (*)(), double>') vector(_InputIterator __first, _InputIterator __last, ^ /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/stl_vector.h:264:7: note: candidate constructor not viable: requires single argument '__a', but 2 arguments were provided vector(const allocator_type& __a) _GLIBCXX_NOEXCEPT ^ /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/stl_vector.h:318:7: note: candidate constructor not viable: requires single argument '__x', but 2 arguments were provided vector(const vector& __x) ^ /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/stl_vector.h:335:7: note: candidate constructor not viable: requires single argument '__x', but 2 arguments were provided vector(vector&& __x) noexcept ^ /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/stl_vector.h:253:7: note: candidate constructor not viable: requires 0 arguments, but 2 were provided vector() ^ 1 error generated.
-
Da fehlen die Klammern beim Funktionsaufruf von
numeric_limits<double>::max()...
-
Uhh, wie doof von mir... Aus den Fehlermeldungen habe ich es nicht wirklich rauslesen können... Danke Dir!