Title: Cannot return non_const reference to contained value for uninitialized optional variable type. · Issue #111 · boostorg/optional · GitHub
Open Graph Title: Cannot return non_const reference to contained value for uninitialized optional variable type. · Issue #111 · boostorg/optional
X Title: Cannot return non_const reference to contained value for uninitialized optional variable type. · Issue #111 · boostorg/optional
Description: I'm having an issue with the following code: From boost/optional.hpp - lines 1267-1281 (problem lines marked with ~) // Returns a reference to the value if this is initialized, otherwise, // the behaviour is UNDEFINED // No-throw referen...
Open Graph Description: I'm having an issue with the following code: From boost/optional.hpp - lines 1267-1281 (problem lines marked with ~) // Returns a reference to the value if this is initialized, otherwise, // the be...
X Description: I'm having an issue with the following code: From boost/optional.hpp - lines 1267-1281 (problem lines marked with ~) // Returns a reference to the value if this is initialized, otherwise, // th...
Opengraph URL: https://github.com/boostorg/optional/issues/111
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Cannot return non_const reference to contained value for uninitialized optional variable type.","articleBody":"I'm having an issue with the following code:\r\n\r\nFrom boost/optional.hpp - lines 1267-1281 (problem lines marked with ~)\r\n\r\n\u003e // Returns a reference to the value if this is initialized, otherwise,\r\n // the behaviour is UNDEFINED\r\n // No-throw\r\n reference_const_type get() const { BOOST_ASSERT(this-\u003eis_initialized()) ; return this-\u003eget_impl(); }\r\n~ reference_type get() { BOOST_ASSERT(this-\u003eis_initialized()) ; return this-\u003eget_impl(); }\r\n\r\n\u003e /// Returns a copy of the value if this is initialized, 'v' otherwise\r\n reference_const_type get_value_or ( reference_const_type v ) const { return this-\u003eis_initialized() ? get() : v ; }\r\n reference_type get_value_or ( reference_type v ) { return this-\u003eis_initialized() ? get() : v ; }\r\n\r\n\u003e /// Returns a pointer to the value if this is initialized, otherwise,\r\n // the behaviour is UNDEFINED\r\n // No-throw\r\n pointer_const_type operator-\u003e() const { BOOST_ASSERT(this-\u003eis_initialized()) ; return this-\u003eget_ptr_impl() ; }\r\n~ pointer_type operator-\u003e() { BOOST_ASSERT(this-\u003eis_initialized()) ; return this-\u003eget_ptr_impl() ; }\r\n\r\nThe code returns non-const reference and pointer. These used for getting a reference to the contained variable holding the type presumably so it can be modified. (this is my case). BUT, the BOOST_ASSERT traps if the variable isn't initialized. This makes it impossible to modify the contained value. The is necessary in the context of the serialization library. ","author":{"url":"https://github.com/robertramey","@type":"Person","name":"robertramey"},"datePublished":"2023-09-05T21:12:37.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/111/optional/issues/111"}
| 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:7cc6486a-7fd2-e7c7-885f-19ab0dd7564d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BE7C:36EFB:18E02F:21F022:6981F066 |
| html-safe-nonce | d7e6c1e558794a1285614d73dcadd1d802c7fdd65bd12a633f1ac49fb975a867 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRTdDOjM2RUZCOjE4RTAyRjoyMUYwMjI6Njk4MUYwNjYiLCJ2aXNpdG9yX2lkIjoiNjYyMjYwNzUxNTExOTEyMDQ4NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ec9f08941fb9a9b9011e92e142e63a26bf40a2b7b7dd1bef6b03f65d0e3dc2f4 |
| hovercard-subject-tag | issue:1882731864 |
| 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/boostorg/optional/111/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8ada7a22a0be8cba164adc92a752ac19885c69029ff64daa73b91c899b1923d3/boostorg/optional/issues/111 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8ada7a22a0be8cba164adc92a752ac19885c69029ff64daa73b91c899b1923d3/boostorg/optional/issues/111 |
| og:image:alt | I'm having an issue with the following code: From boost/optional.hpp - lines 1267-1281 (problem lines marked with ~) // Returns a reference to the value if this is initialized, otherwise, // the be... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | robertramey |
| hostname | github.com |
| expected-hostname | github.com |
| None | ebfdf8d3e0fd17b103f41cc6696d84938694ebebdfecaf11fe00dbe4a9785801 |
| turbo-cache-control | no-preview |
| go-import | github.com/boostorg/optional git https://github.com/boostorg/optional.git |
| octolytics-dimension-user_id | 3170529 |
| octolytics-dimension-user_login | boostorg |
| octolytics-dimension-repository_id | 7589934 |
| octolytics-dimension-repository_nwo | boostorg/optional |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7589934 |
| octolytics-dimension-repository_network_root_nwo | boostorg/optional |
| 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 | ac4541b58a15c144d6ed4fc868b9ea4bb99bb4b6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width