<div dir="ltr">On Mon, Oct 21, 2013 at 11:28 AM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div class="h5">On Mon, Oct 21, 2013 at 6:34 AM, Stephen Kelly <span dir="ltr"><<a href="mailto:steveire@gmail.com" target="_blank">steveire@gmail.com</a>></span> wrote:<br>
</div></div><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5">
<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>
Hi,<br>
<br>
the libcxx source has a comment that compiler support is needed for<br>
std::underlying_type.<br>
<br>
Is there some reason that something like the following can't work?<br>
<br>
<br>
 #include <type_traits><br>
<br>
 template <int> struct int_for_size;<br>
 template <>    struct int_for_size<1> { typedef signed char Signed; typedef<br>
unsigned char Unsigned; };<br>
 template <>    struct int_for_size<2> { typedef short Signed; typedef<br>
unsigned short Unsigned; };<br>
 template <>    struct int_for_size<4> { typedef int Signed; typedef<br>
unsigned int Unsigned; };<br>
 template <>    struct int_for_size<8> { typedef long long Signed; typedef<br>
long long Unsigned; };<br>
<br>
 template<typename T, bool><br>
 struct ApplySign<br>
 {<br>
   typedef typename int_for_size<sizeof(T)>::Signed Type;<br>
 };<br>
 template<typename T><br>
 struct ApplySign<T, false><br>
 {<br>
   typedef typename int_for_size<sizeof(T)>::Unsigned Type;<br>
 };<br>
<br>
 template<typename T><br>
 struct UnderLyingType<br>
 {<br>
     typedef typename ApplySign<T, std::is_signed<T>::value>::Type Type;<br>
 };<br>
<br>
 enum Something {<br>
   foo<br>
 };<br>
<br>
 int main()<br>
 {<br>
   UnderLyingType<Something>::Type s = 9;<br>
   return 0;<br>
 }<br></blockquote><div><br></div></div></div><div>enum E1 : long {};</div><div>static_assert(std::is_same<std::underlying_type<E1>::type, long>::value, ""); // ok</div><div>static_assert(std::is_same<UnderLyingType<E1>::Type, long>::value, ""); // fails<br>

</div><div><br></div><div>enum E2 : char {};</div><div><div>static_assert(std::is_same<std::underlying_type<E2>::type, char>::value, ""); // ok</div><div>static_assert(std::is_same<UnderLyingType<E2>::Type, char>::value, ""); // fails</div>
</div></div></div></div></blockquote><div><br></div><div>*fixed*</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra">
<div class="gmail_quote"><div>
</div><div class="im"><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">
<br>
Thanks,<br>
<br>
Steve.<br>
<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote></div></div><br></div></div>
</blockquote></div><br></div></div>