Just recently embraced user-defined literals for my strongy-typed units of time (e.g. 10_ms, 100_us, 1_ns). My time types have always required explicit constructors to make call sites clear and this outcome is the best of all worlds. Except the extra function call, of course...
-
-
Vastauksena käyttäjälle @Donzanoid
User defined literal functions need to be constexpr correct? Or at the very least implemented much like template code (inlined, header only, etc) so that should eliminate the function call at least?
1 vastaus 0 uudelleentwiittausta 0 tykkäystä -
Vastauksena käyttäjälle @actualGraphite
Nope. Not in debug builds.
1 vastaus 0 uudelleentwiittausta 0 tykkäystä -
Vastauksena käyttäjälle @Donzanoid
You can force inline though right?
1 vastaus 0 uudelleentwiittausta 0 tykkäystä -
Vastauksena käyttäjälle @actualGraphite
Not in debug builds.
1 vastaus 0 uudelleentwiittausta 0 tykkäystä -
Vastauksena käyttäjille @Donzanoid ja @actualGraphite
literals can be marked constexpr and if they are assigned to a constexpr value, they will be evaluated in constexpr just like any other function. This doesn't help when doing "MyFunction(10_us)". You'd have to hoist the 10_us up into a constexpr first. =(
3 vastausta 0 uudelleentwiittausta 0 tykkäystä
I use hash literals (something like "someString"_hash), and it works in case statements and explicitly declared constexpr values. But what I often want is "FindAnimation("anim"_hash)" or something like that. Unfortunately doesn't even work in release on msvc. =(
Lataaminen näyttää kestävän hetken.
Twitter saattaa olla ruuhkautunut tai ongelma on muuten hetkellinen. Yritä uudelleen tai käy Twitterin tilasivulla saadaksesi lisätietoja.