<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Vector aus Pairs mit numerical_limits]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe folgenden Code</p>
<pre><code>#include &lt;vector&gt;
#include &lt;utility&gt;
#include &lt;limits&gt;

using namespace std;

int main(int argc, char **args)
{
  int dim = 4;
  // funktioniert nicht, da will ich hin
  // vector&lt;pair&lt;double, double&gt;&gt; c1(dim,
  //                                 make_pair(numeric_limits&lt;double&gt;::max,
  //                                           numeric_limits&lt;double&gt;::lowest));

  vector&lt;pair&lt;double, double&gt;&gt; c2(dim, make_pair(0.5, 1.5)); // (1) funktioniert

  vector&lt;pair&lt;double, double&gt;&gt; c3(dim, make_pair(numeric_limits&lt;double&gt;::max, 1.5)); // (2) funktioniert nicht

  return 0;
}
</code></pre>
<p>(1) funktioniert mit g++ und clang++ -std=c++11, warum aber nicht (2)? numeric_limits&lt;T&gt;::max gibt T zurück, hier also double. Aus meiner Sicht, sollte (2) damit von den Typen her das gleiche wie (1) sein.</p>
<p>Danke,</p>
<p>Florian</p>
<p>Fehlerausgaben:</p>
<pre><code>% clang++ --std=c++11 test.cpp
test.cpp:20:32: error: no matching constructor for initialization of 'vector&lt;pair&lt;double, double&gt; &gt;'
  vector&lt;pair&lt;double, double&gt;&gt; c3(dim, make_pair(numeric_limits&lt;double&gt;::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&lt;typename __decay_and_strip&lt;double (&amp;)()&gt;::__type, typename
      __decay_and_strip&lt;double&gt;::__type&gt;' to 'const allocator_type' (aka 'const std::allocator&lt;std::pair&lt;double, double&gt; &gt;') for 2nd argument
      vector(size_type __n, const allocator_type&amp; __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&lt;typename __decay_and_strip&lt;double (&amp;)()&gt;::__type, [...]&gt;' to 'const pair&lt;double, [...]&gt;' for 2nd argument
      vector(size_type __n, const value_type&amp; __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&lt;std::pair&lt;double, double&gt;,
      std::allocator&lt;std::pair&lt;double, double&gt; &gt; &gt;' for 1st argument
      vector(const vector&amp; __x, const allocator_type&amp; __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&lt;std::pair&lt;double, double&gt;,
      std::allocator&lt;std::pair&lt;double, double&gt; &gt; &gt;' for 1st argument
      vector(vector&amp;&amp; __rv, const allocator_type&amp; __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&lt;value_type&gt;' for 1st argument
      vector(initializer_list&lt;value_type&gt; __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&lt;double (*)(), double&gt;')
        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&amp; __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&amp; __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&amp;&amp; __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.
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/330494/vector-aus-pairs-mit-numerical_limits</link><generator>RSS for Node</generator><lastBuildDate>Fri, 03 Jul 2026 06:12:15 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/330494.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 13 Jan 2015 10:01:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Vector aus Pairs mit numerical_limits on Tue, 13 Jan 2015 10:01:35 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe folgenden Code</p>
<pre><code>#include &lt;vector&gt;
#include &lt;utility&gt;
#include &lt;limits&gt;

using namespace std;

int main(int argc, char **args)
{
  int dim = 4;
  // funktioniert nicht, da will ich hin
  // vector&lt;pair&lt;double, double&gt;&gt; c1(dim,
  //                                 make_pair(numeric_limits&lt;double&gt;::max,
  //                                           numeric_limits&lt;double&gt;::lowest));

  vector&lt;pair&lt;double, double&gt;&gt; c2(dim, make_pair(0.5, 1.5)); // (1) funktioniert

  vector&lt;pair&lt;double, double&gt;&gt; c3(dim, make_pair(numeric_limits&lt;double&gt;::max, 1.5)); // (2) funktioniert nicht

  return 0;
}
</code></pre>
<p>(1) funktioniert mit g++ und clang++ -std=c++11, warum aber nicht (2)? numeric_limits&lt;T&gt;::max gibt T zurück, hier also double. Aus meiner Sicht, sollte (2) damit von den Typen her das gleiche wie (1) sein.</p>
<p>Danke,</p>
<p>Florian</p>
<p>Fehlerausgaben:</p>
<pre><code>% clang++ --std=c++11 test.cpp
test.cpp:20:32: error: no matching constructor for initialization of 'vector&lt;pair&lt;double, double&gt; &gt;'
  vector&lt;pair&lt;double, double&gt;&gt; c3(dim, make_pair(numeric_limits&lt;double&gt;::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&lt;typename __decay_and_strip&lt;double (&amp;)()&gt;::__type, typename
      __decay_and_strip&lt;double&gt;::__type&gt;' to 'const allocator_type' (aka 'const std::allocator&lt;std::pair&lt;double, double&gt; &gt;') for 2nd argument
      vector(size_type __n, const allocator_type&amp; __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&lt;typename __decay_and_strip&lt;double (&amp;)()&gt;::__type, [...]&gt;' to 'const pair&lt;double, [...]&gt;' for 2nd argument
      vector(size_type __n, const value_type&amp; __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&lt;std::pair&lt;double, double&gt;,
      std::allocator&lt;std::pair&lt;double, double&gt; &gt; &gt;' for 1st argument
      vector(const vector&amp; __x, const allocator_type&amp; __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&lt;std::pair&lt;double, double&gt;,
      std::allocator&lt;std::pair&lt;double, double&gt; &gt; &gt;' for 1st argument
      vector(vector&amp;&amp; __rv, const allocator_type&amp; __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&lt;value_type&gt;' for 1st argument
      vector(initializer_list&lt;value_type&gt; __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&lt;double (*)(), double&gt;')
        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&amp; __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&amp; __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&amp;&amp; __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.
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2437288</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2437288</guid><dc:creator><![CDATA[Horus107]]></dc:creator><pubDate>Tue, 13 Jan 2015 10:01:35 GMT</pubDate></item><item><title><![CDATA[Reply to Vector aus Pairs mit numerical_limits on Tue, 13 Jan 2015 10:14:11 GMT]]></title><description><![CDATA[<p>Da fehlen die Klammern beim Funktionsaufruf von <code>numeric_limits&lt;double&gt;::max()</code> ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2437292</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2437292</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Tue, 13 Jan 2015 10:14:11 GMT</pubDate></item><item><title><![CDATA[Reply to Vector aus Pairs mit numerical_limits on Tue, 13 Jan 2015 10:28:37 GMT]]></title><description><![CDATA[<p>Uhh, wie doof von mir... Aus den Fehlermeldungen habe ich es nicht wirklich rauslesen können... Danke Dir!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2437294</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2437294</guid><dc:creator><![CDATA[Horus107]]></dc:creator><pubDate>Tue, 13 Jan 2015 10:28:37 GMT</pubDate></item></channel></rss>