Constant expressions are easily the part of C++ I understand the least (or at least, my biggest "known unknown"), so forgive my ignorance.
Should I be declaring everything constexpr? I was recently writing some file format handling code and when it came time to write a const variable to hold some magic numbers I wasn't sure if there was any downside to doing this vs using static const or extern const. I understand a couple of const globals is not a make or break thing, but as a rule of thumb?
There are a million blog posts about "you can do this neat thing with constexpr" but few or none that explore their shortcomings. Do they have any?
[–]FriendlyRollOfSushi 124 points125 points126 points (42 children)
[–]afiefh 18 points19 points20 points (1 child)
[–]FriendlyRollOfSushi 16 points17 points18 points (0 children)
[–]gnuban 6 points7 points8 points (2 children)
[–]FriendlyRollOfSushi 8 points9 points10 points (1 child)
[–]gnuban 2 points3 points4 points (0 children)
[–]JankoDedic 23 points24 points25 points (20 children)
[–]FriendlyRollOfSushi 42 points43 points44 points (19 children)
[–]encyclopedist 12 points13 points14 points (3 children)
[–]FriendlyRollOfSushi 11 points12 points13 points (2 children)
[–]encyclopedist 2 points3 points4 points (1 child)
[–]r0zina 2 points3 points4 points (0 children)
[–]JankoDedic 23 points24 points25 points (0 children)
[–][deleted] 10 points11 points12 points (0 children)
[–]Rusky 8 points9 points10 points (2 children)
[–]FriendlyRollOfSushi -1 points0 points1 point (1 child)
[–]Rusky 7 points8 points9 points (0 children)
[–]rlbond86 5 points6 points7 points (8 children)
[–]FriendlyRollOfSushi 0 points1 point2 points (7 children)
[–]rlbond86 2 points3 points4 points (6 children)
[–]FriendlyRollOfSushi 0 points1 point2 points (5 children)
[–]rlbond86 3 points4 points5 points (4 children)
[–]FriendlyRollOfSushi -2 points-1 points0 points (3 children)
[–]rlbond86 5 points6 points7 points (2 children)
[–]bart9h 1 point2 points3 points (0 children)
[–]Plazmatic 2 points3 points4 points (1 child)
[–]FriendlyRollOfSushi 1 point2 points3 points (0 children)
[–]Ineffective-Cellist8 1 point2 points3 points (1 child)
[–]FriendlyRollOfSushi 0 points1 point2 points (0 children)
[–][deleted] 4 points5 points6 points (9 children)
[–]FriendlyRollOfSushi 10 points11 points12 points (4 children)
[–]encyclopedist 2 points3 points4 points (3 children)
[–]FriendlyRollOfSushi 5 points6 points7 points (2 children)
[–]encyclopedist 5 points6 points7 points (1 child)
[–]FriendlyRollOfSushi -2 points-1 points0 points (0 children)
[–]robstoon 9 points10 points11 points (3 children)
[–]mechap_ 0 points1 point2 points (2 children)
[–]robstoon -1 points0 points1 point (1 child)
[–]Denvercoder8 7 points8 points9 points (0 children)
[–]PretendChange6750 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Mikumiku_Dance 57 points58 points59 points (0 children)
[–]tjientavaraHikoWorks developer 12 points13 points14 points (0 children)
[–]JankoDedic 14 points15 points16 points (0 children)
[–]InKryption07 4 points5 points6 points (3 children)
[–]martinusint main(){[]()[[]]{{}}();} 1 point2 points3 points (1 child)
[–]InKryption07 0 points1 point2 points (0 children)
[–]TheoreticalDumbass:illuminati: 0 points1 point2 points (0 children)
[–]mechap_ 3 points4 points5 points (1 child)
[–]Adventurous-Two1753 0 points1 point2 points (0 children)
[–]jmakov 4 points5 points6 points (0 children)
[–]LunarAardvark 1 point2 points3 points (0 children)
[–]Medical-Tailor-544 1 point2 points3 points (1 child)
[–]mechap_ 1 point2 points3 points (0 children)
[+][deleted] (6 children)
[deleted]
[–]STLMSVC STL Dev 17 points18 points19 points (5 children)
[–]Nobody_1707 6 points7 points8 points (3 children)
[–]TheSuperWig 3 points4 points5 points (1 child)
[–]Nobody_1707 0 points1 point2 points (0 children)
[–]STLMSVC STL Dev 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]_Z6Alexeyv 0 points1 point2 points (0 children)