Is thin kind of implementation safe(reimplement max with auto and type_traits)
<pre><code>#include &lt;iostream&gt;
#include &lt;type_traits&gt;

#include &lt;boost/type_traits.hpp&gt;

template&lt;typename T, typename U&gt;
struct promote
{
  private:
    typedef typename std::conditional&lt;(sizeof(T) &gt; sizeof(U)), T, U&gt;::type Bigger;
    typedef typename std::add_const&lt;Bigger&gt;::type BConst;

  public:
    //because mingw4.6.2 do not implement std::add_reference
    typedef typename boost::add_reference&lt;BConst&gt;::type type;
};

template&lt;typename T, typename U&gt;
auto max(T const &amp;a, U const &amp;b)-&gt;typename promote&lt;T, U&gt;::type
{
  return a &gt; b ? a : b;
}

int main(int argc, char *argv[])
{
  std::cout&lt;&lt;max(3, 4.5)&lt;&lt;std::endl;
  std::cout&lt;&lt;max(4.5, 3)&lt;&lt;std::endl;

  return 0;
}
</code></pre>

<p>std::max of mingw4.6.2</p>

<pre><code>template&lt;typename T&gt;
inline T const&amp; max(T const &amp;a, T const &amp;b)
{
  return a &gt; b ? a : b;
}
</code></pre>

<p>This will give me warning messages</p>

<p>main.cpp:27:24: warning: returning reference to temporary [enabled by default]</p>

<p>main.cpp:27:24: warning: returning reference to temporary [enabled by default]</p>

<p>Compiler is migw4.6.2, OS is win7 64bits</p>

<p>second version, only support scalar type</p>

<pre><code>template&lt;typename T, typename U&gt;
struct promote
{
   typedef typename std::conditional&lt;(sizeof(T) &gt; sizeof(U)), T, U&gt;::type type;

};

template&lt;typename T, typename U&gt;
inline typename promote&lt;T, U&gt;::type max(T a, U b)
{
  static_assert(std::is_scalar&lt;T&gt;::value, "inhomogeneous max only support scalar type");
  static_assert(std::is_scalar&lt;U&gt;::value, "inhomogeneous max only support scalar type");

  return a &gt; b ? a : b;
}
</code></pre>

<p>The other solution are using SFINAE and boost::mpl to do some "overload".
I think I would just explicitly name the type of std::max in the real case</p>
