-
m-relay<jeffro256:monero.social> @vtnerd do you think compilers will be smart enough to unroll the `for_each` in this function into a single O(1) lookup?
-
m-relay<vtnerd:monero.social> Which function?
-
m-relay<jeffro256:monero.social> Lol I forgot to link: github.com/jeffro256/monero/blob/2e…ff05855bd/src/common/variant.h#L175
-
m-relay<vtnerd:monero.social> So you want this to "jump" to the element given as an integer? It _might_ do that, but it could also punt and generate a generic function with `which` as a runtime value. My best guess is that it will do the latter, but I dunno it's plausible that everything gets unlined and optimized
-
m-relay<vtnerd:monero.social> *inlined
-
m-relay<jeffro256:monero.social> Yes that's the goal
-
m-relay<jeffro256:monero.social> Without writing an explicit `switch/case` for different variant types
-
m-relay<vtnerd:monero.social> You also should consider a switch to std::variant, it has an emplace function which does exactly this, and has a std::monostate. One downside is that it can have "valueless" on exception whereas boost guarantees a value even with exceptions
-
m-relay<jeffro256:monero.social> Oh we DID move to c++17....
-
m-relay<vtnerd:monero.social> Yeah, that's what I was thinking. But the differences might not be worth it. But it does have an emplace, which looks k to be the goal here
-
m-relay<jeffro256:monero.social> Oh but that emplace requires you to know the index at compile time
-
m-relay<jeffro256:monero.social> I was looking for a way to value initialize in O(1) which a run-time index, specifically to be used in deserialization
-
m-relay<jeffro256:monero.social> s/which/with
-
m-relay<vtnerd:monero.social> Ah right, you wanted the runtime value. I think most compilers are unlikely to create a jump table, probably similar to an if/else ladder, but I don't know it's probably close
-
m-relay<jeffro256:monero.social> Thanks for looking btw