Title: Constexpr does not enforce compile-time evaluation · Issue #276 · algorithmica-org/algorithmica · GitHub
Open Graph Title: Constexpr does not enforce compile-time evaluation · Issue #276 · algorithmica-org/algorithmica
X Title: Constexpr does not enforce compile-time evaluation · Issue #276 · algorithmica-org/algorithmica
Description: This book unfortunately perpetuates the widely held belief that putting a constexpr keyword on code will, on its own, force code to be evaluated at compile time. This is inaccurate. You need C++20's consteval for that. What constexpr act...
Open Graph Description: This book unfortunately perpetuates the widely held belief that putting a constexpr keyword on code will, on its own, force code to be evaluated at compile time. This is inaccurate. You need C++20'...
X Description: This book unfortunately perpetuates the widely held belief that putting a constexpr keyword on code will, on its own, force code to be evaluated at compile time. This is inaccurate. You need C++20&...
Opengraph URL: https://github.com/algorithmica-org/algorithmica/issues/276
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Constexpr does not enforce compile-time evaluation","articleBody":"This book unfortunately perpetuates the widely held belief that putting a constexpr keyword on code will, on its own, force code to be evaluated at compile time. This is inaccurate. You need C++20's consteval for that.\r\n\r\nWhat constexpr actually does is to constrain code into a subset of the language that _can_ be evaluated at compile time. This, in turn, lets you use constexpr functions and expressions in a context where the output expression _must_ be evaluated at compile time for the program to be correct according to the rules of the language. Think about, for example, computing template non-type parameters.\r\n\r\nCompilers are not forced to evaluate constexpr operations at compile-time, and indeed, [for a sufficiently complex expression, they won't](https://godbolt.org/z/zG4b1jfe6). Conversely, compilers were able to evaluate expressions at compile time a long time before constexpr was a thing, and will commonly perform the associated const-propagation optimization on code where constexpr is not present.\r\n\r\nAll in all, the only way constexpr may benefit program optimization is that it forces you to constrain yourself into a subset of the language which is known to be amenable to const-propagation on all modern compilers, and lets you get a compiler error otherwise. This is useful, but not as useful as the current text asserts, so please consider amending it and pointing to consteval instead for the kind of optimizations that you are discussing in the book.","author":{"url":"https://github.com/HadrienG2","@type":"Person","name":"HadrienG2"},"datePublished":"2024-03-23T18:54:08.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/276/algorithmica/issues/276"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ac053ab9-1720-d0d6-bbad-b97524706b10 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B56E:3B54D2:3657F9:49AB9A:697CDF54 |
| html-safe-nonce | 38e2df5a24da214d6da50813a46e89910555205fbcb7b87699c0826606fae8a1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNTZFOjNCNTREMjozNjU3Rjk6NDlBQjlBOjY5N0NERjU0IiwidmlzaXRvcl9pZCI6IjM0NDA5MzEzODE4ODA2MTA2NDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 83df13ce89e7622f5bbb379e7d99f332275eb09dfc99a73ebf30e7fd6ab0cbab |
| hovercard-subject-tag | issue:2204003729 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/algorithmica-org/algorithmica/276/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cddb6c287f92d5af5e8f82fbcc77ddcc018b107e61a8a91cfa4e95e6d92ab29f/algorithmica-org/algorithmica/issues/276 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cddb6c287f92d5af5e8f82fbcc77ddcc018b107e61a8a91cfa4e95e6d92ab29f/algorithmica-org/algorithmica/issues/276 |
| og:image:alt | This book unfortunately perpetuates the widely held belief that putting a constexpr keyword on code will, on its own, force code to be evaluated at compile time. This is inaccurate. You need C++20'... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | HadrienG2 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f20df5019a7f846ce01350c443b1b5209bcc8b08d1ff80f92fdef440a0c7c89 |
| turbo-cache-control | no-preview |
| go-import | github.com/algorithmica-org/algorithmica git https://github.com/algorithmica-org/algorithmica.git |
| octolytics-dimension-user_id | 51334463 |
| octolytics-dimension-user_login | algorithmica-org |
| octolytics-dimension-repository_id | 333536823 |
| octolytics-dimension-repository_nwo | algorithmica-org/algorithmica |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 333536823 |
| octolytics-dimension-repository_network_root_nwo | algorithmica-org/algorithmica |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 0f08fae6208283a46e6e5febf9878b9cdddfaa23 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width