Discussion:
[Oiio-dev] OIIO::ustring in switch statement
Søren Ragsdale
2018-10-12 10:53:54 UTC
Permalink
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
case foo: break;
^
note: ‘foo’ was not declared ‘constexpr’
const static OIIO::ustring foo("foo");
Larry Gritz
2018-10-12 14:07:37 UTC
Permalink
Yeah, I dont think this would work for std::string, either. C++ 'switch' just isn't as general as you might want here.
Post by Søren Ragsdale
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
Post by Søren Ragsdale
case foo: break;
^
note: ‘foo’ was not declared ‘constexpr’
const static OIIO::ustring foo("foo");
--
Larry Gritz
***@larrygritz.com
Loading...