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ä -
you don't want constexpr but consteval:https://gcc.godbolt.org/z/8rv8Kq
2 vastausta 0 uudelleentwiittausta 0 tykkäystä
Until recently we’d not been targeting c++20, so consteval was unavailable. We recently switched to 20 so I may need to re-evaluate this.
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.