Discussion:
[Oiio-dev] 回复: OIIO::ustring in switch statement
Negroove
2018-10-13 03:55:51 UTC
Permalink
If you only want to 'switch' the hash of ustring/string, I think it's possible. You can implement a compile-time script to generate static hash values for 'case'. The compare of ustring is based on run-time allocated pointers, using if-else-if sequence to compare is very fast. So I suspect if using switch-case can get any benefits. ------------------ Ô­ÊŒÓÊŒþ ------------------
·¢ŒþÈË: "S&#xF8;ren Ragsdale"<***@gmail.com>
·¢ËÍʱŒä: 2018Äê10ÔÂ12ÈÕ(ÐÇÆÚÎå) ÍíÉÏ6:53
ÊÕŒþÈË: "OpenImageIO developers"<oiio-***@lists.openimageio.org>;
Ö÷Ìâ: [Oiio-dev] OIIO::ustring in switch statement


Is there any way to use an OIIO::ustring in a switch statement? I'm guessing that it's not possible because the hashes for these strings are generated at compile time.

const static OIIO::ustring foo("foo");
const static OIIO::ustring bar("bar");
switch (foo) {
case foo: break;
case bar: break;
default: break;
}


error: the value of ¡®foo¡¯ is not usable in a constant expression
&#xA0; case foo: break;
&#xA0; &#xA0; &#xA0; &#xA0;^
note: ¡®foo¡¯ was not declared ¡®constexpr¡¯
&#xA0;const static OIIO::ustring foo("foo");

Loading...