<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Apr 29, 2015 at 4:04 PM, Robert Maynard <span dir="ltr"><<a href="mailto:robert.maynard@kitware.com" target="_blank">robert.maynard@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">"<br>
Following a breaking change between the C++98/03 and C++11 standards,<br>
using explicit template arguments to call make_pair()—as in<br>
make_pair<int, int>(x, y)—typically does not compile in Visual C++ in<br>
Visual Studio 2012. The solution is to always call make_pair() without<br>
explicit template arguments—as in make_pair(x, y). Providing explicit<br>
template arguments defeats the purpose of the function. If you require<br>
precise control over the resulting type, use pair instead<br>
of make_pair—as in pair<short, short>(int1, int2).<br></blockquote><div><br></div><div>Thanks for finding that. That explains why the std::make_pair<double, X*>(double, X*) call failed. Strange, but I see they're justifying it.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Another breaking change between the C++98/03 and C++11 standards: When<br>
A is implicitly convertible to B and B is implicitly convertible to C,<br>
but A is not implicitly convertible to C, C++98/03 and Visual C++ 2010<br>
permitted pair<A, X> to be converted (implicitly or explicitly) to<br>
pair<C, X>. (The other type, X, is not of interest here, and this is<br>
not specific to the first type in the pair.) Because C++11 and Visual<br>
C++ in Visual Studio 2012 detect that A is not implicitly convertible<br>
to C, they remove the pair conversion from overload resolution. This<br>
is a positive change for many scenarios. For example, overloading<br>
func(const pair<int, int>&) and func(const pair<string, string>&), and<br>
calling func() with pair<const char *, const char *> will compile with<br>
this change. However, this change breaks code that relied on<br>
aggressive pair conversions. Such code can typically be fixed by<br>
performing one part of the conversion explicitly—for example, by<br>
passing make_pair(static_cast<B>(a), x) to a function that expects<br>
pair<C, X>.<br>
"<br></blockquote><div><br></div><div>I'm still missing something here. One on of my attempts to get this to compile simultaneously across all of our windows dashboards, this call was failing:</div><div><br></div><div>std::pair<double, X*>(someDouble, NULL);</div><div><br></div><div>As I understand it, if NULL is defined as either (int)0, (void*)0, or nullptr (depending on implementation/standard), all of those expressions are implicitly convertible to X* without going through an intermediate, right? To fix it, I had to explicitly cast the NULL to X* for compilation to succeed. What am I missing here?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
The reason that we haven't seen this with other compilers is either<br>
they haven't enabled C++11 (with c++11 standard library) or they<br>
compile options are lax and allow this behavior.</blockquote><div><br></div><div>My guess is the latter. Backward compatibility is a nice thing to have in a compiler ;)</div><div><br></div>On Wed, Apr 29, 2015 at 5:52 PM, David Cole <span dir="ltr"><<a href="mailto:DLRdave@aol.com" target="_blank">DLRdave@aol.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Thanks for the discussion.<br><br>I did try what you said, and I do reproduce the error you saw, ... but<br>I still say it's not a general problem with double and make_pair.<br></blockquote><div><br></div><div>Correct. It'll happen with any explicit type specification on make_pair.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">make_pair ought to be use-able without specifying types. If you have<br>to specify the type of a pair, then you should just use pair<type1,<br>type2> directly as you've ended up with. The extra cast you needed for<br>VS2010 is the real shame.<br></blockquote><div><br></div><div>Agreed. I only added the explicit template arguments as a hint that the NULL should be cast to X*. You can imagine my surprise when that failed because it didn't like the 'double'!</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">I will propose a patch that rephrases the in-code comments about this<br>if nobody else has the time to do so.<br></blockquote><div><br></div><div>I can see about making the comment I introduced more palatable (I thought you were referring to the commit message earlier...).</div><div><br></div><div>BTW, if my comments were enough of a turn-off to spark this thread, you may want to grep the code for things like "stupid", "dumb", "moron", "idiot", "s***" and "f***". These all appear in our source code (albeit the stronger language is in contributed modules) and are significantly stronger than any language introduced by my patch. Some are even directed at poor ol' Windows. Might want to check those out and see if you want to air any further grievances ;)</div><div><br></div><div>Dave </div></div></div></div>