{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/bond/pulls/comments/181250289","pull_request_review_id":111832474,"id":181250289,"diff_hunk":"@@ -14,143 +20,395 @@ namespace bond\n \n BOND_NORETURN void NothingException();\n \n+namespace detail\n+{\n \n-/// @brief Type used for fields with default value of 'nothing'\n-/// See [User's Manual](../../manual/bond_cpp.html#default-value-of-nothing)\n template <typename T>\n-class maybe\n+class maybe_common\n {\n public:\n-    typedef T value_type;\n+    /// @brief The type of the value that may be inside the maybe.\n+    using value_type = T;\n \n-    /// @brief Default constructor\n-    maybe()\n-        : _nothing(true)\n-    {}\n-\n-    /// @brief Move constructor\n-    maybe(maybe&& that) BOND_NOEXCEPT_IF(std::is_nothrow_move_constructible<T>::value)\n-        : _value(std::move(that._value)),\n-          _nothing(std::move(that._nothing))\n+    /// @brief Check if this object contains nothing.\n+    /// @return true if this holds nothing; otherwise false.\n+    bool is_nothing() const BOND_NOEXCEPT\n     {\n-        that._nothing = true;\n+        return !static_cast<bool>(_value);\n     }\n \n-    template <typename Allocator>\n-    maybe(maybe&& that, const Allocator& alloc)\n-        : _value(std::move(that._value), alloc),\n-          _nothing(that._nothing)\n+    /// @brief Check if this object contains a value.\n+    /// @return true if this object hold a value; otherwise false.\n+    /// @since 8.0.0\n+    explicit operator bool() const BOND_NOEXCEPT\n     {\n-        that._nothing = true;\n+        return !is_nothing();\n     }\n \n-    maybe(const maybe& that) = default;\n-    maybe& operator=(const maybe& that) = default;\n+    /// @brief Set to nothing.\n+    void set_nothing()\n+    {\n+        _value = boost::none;\n+    }\n \n-    /// @brief Constructor from a value T\n-    explicit\n-    maybe(const T& value)\n-        : _value(value),\n-          _nothing(false)\n+    /// @brief Construct a value in place.\n+    ///\n+    /// @since 8.0.0\n+    template<typename... Args>\n+    T& emplace(Args&&... args)\n     {\n+        _value.emplace(std::forward<Args>(args)...);\n+        return *_value;\n     }\n \n-    template <typename Allocator>\n-    explicit maybe(const Allocator& alloc)\n-        : _value(alloc),\n-          _nothing(true)\n-    {}\n+    /// @brief Get a reference to the value.\n+    /// @throw NothingException if the object contains nothing\n+    T& value()\n+    {\n+        if (is_nothing())\n+        {\n+            NothingException();\n+        }\n \n-    template <typename Allocator>\n-    maybe(const maybe& that, const Allocator& alloc)\n-        : _value(that._value, alloc),\n-          _nothing(that._nothing)\n-    {}\n+        return *_value;\n+    }\n \n-    /// @brief Swap this object with that object\n-    void swap(maybe& that)\n+    /// @brief Get a constant reference to the value.\n+    /// @throw NothingException if the object contains nothing\n+    const T& value() const\n     {\n-        using std::swap;\n+        if (is_nothing())\n+        {\n+            NothingException();\n+        }\n \n-        swap(_nothing, that._nothing);\n-        swap(_value, that._value);\n+        return *_value;\n     }\n \n-    /// @brief Check if this object contains nothing\n-    bool is_nothing() const\n+    /// @brief Get a reference to the value.\n+    ///\n+    /// Will never throw, but has undefined behavior if the object contains\n+    /// nothing.\n+    ///\n+    /// @since 8.0.0\n+    T& value(const std::nothrow_t&) BOND_NOEXCEPT\n     {\n-        return _nothing;\n+        BOOST_ASSERT(!is_nothing());\n+        return *_value;\n     }\n \n-    /// @brief Set to default instance of T and return reference to that value\n-    T& set_value()\n+    /// @brief Get a constant reference to the value.\n+    ///\n+    /// Will never throw, but has undefined behavior if the object contains\n+    /// nothing.\n+    ///\n+    /// @since 8.0.0\n+    const T& value(const std::nothrow_t&) const BOND_NOEXCEPT\n     {\n-        _nothing = false;\n-        return _value;\n+        BOOST_ASSERT(!is_nothing());\n+        return *_value;\n     }\n \n-    /// @brief Set to nothing\n-    void set_nothing()\n+protected:\n+    maybe_common() = default;\n+    maybe_common(const maybe_common&) = default;\n+\n+    explicit maybe_common(const T& value)\n+        : _value(value)\n+    { }\n+\n+    template <typename Alloc>\n+    maybe_common(const T& value, const Alloc& alloc)","path":"cpp/inc/bond/core/maybe.h","position":166,"original_position":166,"commit_id":"ae16537be074fbc10a578e03400dfc8623f15be9","original_commit_id":"aad431043e5b1f17bb09317dceef71e55e1a43f8","user":{"login":"ara-ayvazyan","id":25734498,"avatar_url":"https://avatars1.githubusercontent.com/u/25734498?v=4","gravatar_id":"","url":"https://api.github.com/users/ara-ayvazyan","html_url":"https://github.com/ara-ayvazyan","followers_url":"https://api.github.com/users/ara-ayvazyan/followers","following_url":"https://api.github.com/users/ara-ayvazyan/following{/other_user}","gists_url":"https://api.github.com/users/ara-ayvazyan/gists{/gist_id}","starred_url":"https://api.github.com/users/ara-ayvazyan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ara-ayvazyan/subscriptions","organizations_url":"https://api.github.com/users/ara-ayvazyan/orgs","repos_url":"https://api.github.com/users/ara-ayvazyan/repos","events_url":"https://api.github.com/users/ara-ayvazyan/events{/privacy}","received_events_url":"https://api.github.com/users/ara-ayvazyan/received_events","type":"User","site_admin":false},"body":"Maybe generalize to `maybe_common(U&& value, Args&&.. args)`?","created_at":"2018-04-12T23:25:06Z","updated_at":"2018-04-12T23:25:06Z","html_url":"https://github.com/Microsoft/bond/pull/849#discussion_r181250289","pull_request_url":"https://api.github.com/repos/Microsoft/bond/pulls/849","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/bond/pulls/comments/181250289"},"html":{"href":"https://github.com/Microsoft/bond/pull/849#discussion_r181250289"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/bond/pulls/849"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/bond/pulls/849","id":180092500,"html_url":"https://github.com/Microsoft/bond/pull/849","diff_url":"https://github.com/Microsoft/bond/pull/849.diff","patch_url":"https://github.com/Microsoft/bond/pull/849.patch","issue_url":"https://api.github.com/repos/Microsoft/bond/issues/849","number":849,"state":"open","locked":false,"title":"[c++] Overhaul bond::maybe","user":{"login":"chwarr","id":10605667,"avatar_url":"https://avatars3.githubusercontent.com/u/10605667?v=4","gravatar_id":"","url":"https://api.github.com/users/chwarr","html_url":"https://github.com/chwarr","followers_url":"https://api.github.com/users/chwarr/followers","following_url":"https://api.github.com/users/chwarr/following{/other_user}","gists_url":"https://api.github.com/users/chwarr/gists{/gist_id}","starred_url":"https://api.github.com/users/chwarr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chwarr/subscriptions","organizations_url":"https://api.github.com/users/chwarr/orgs","repos_url":"https://api.github.com/users/chwarr/repos","events_url":"https://api.github.com/users/chwarr/events{/privacy}","received_events_url":"https://api.github.com/users/chwarr/received_events","type":"User","site_admin":false},"body":"bond::maybe now has better support for rvalue-references and allocator\r\npropagation.\r\n\r\nThis implementation also avoids default initializing an instance of T\r\nwhen creating an maybe that holds nothing\r\n\r\nbond::maybe is now implemented in terms of boost::optional. We should be\r\nable to std::optional with minimal effort when Bond requires a minimum\r\nof C++17.\r\n\r\nAdditional changes:\r\n\r\n* Removed a dangerous implicit conversion operator from `bond::maybe<T>`\r\n  to `const T&`. To access a `bond::maybe<T>` value, use\r\n* Added noexcept variants of `bond::maybe<T>::value`.\r\n* Added `bond::maybe<T>::emplace` to construct a maybe's value in place.\r\n* Added various rvalue-reference and allocator-aware constructors and\r\n  assignment operators.\r\n* Added `bond::maybe<T>::operator==(const T&)` to comapre directly to\r\n  instances of `T`.\r\n* Improved test coverage of `set_value()`: it was only effectively\r\n  constructing a new T the first time.\r\n* Added tests for moved-from bond::maybe instances.\r\n* Added tests for allocator propagation.","created_at":"2018-04-07T06:36:05Z","updated_at":"2018-04-12T23:25:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8c65b2a3e9ff597c4a93ec09b6f669fa13317014","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/bond/pulls/849/commits","review_comments_url":"https://api.github.com/repos/Microsoft/bond/pulls/849/comments","review_comment_url":"https://api.github.com/repos/Microsoft/bond/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Microsoft/bond/issues/849/comments","statuses_url":"https://api.github.com/repos/Microsoft/bond/statuses/ae16537be074fbc10a578e03400dfc8623f15be9","head":{"label":"chwarr:chwarr/maybe-default-init","ref":"chwarr/maybe-default-init","sha":"ae16537be074fbc10a578e03400dfc8623f15be9","user":{"login":"chwarr","id":10605667,"avatar_url":"https://avatars3.githubusercontent.com/u/10605667?v=4","gravatar_id":"","url":"https://api.github.com/users/chwarr","html_url":"https://github.com/chwarr","followers_url":"https://api.github.com/users/chwarr/followers","following_url":"https://api.github.com/users/chwarr/following{/other_user}","gists_url":"https://api.github.com/users/chwarr/gists{/gist_id}","starred_url":"https://api.github.com/users/chwarr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chwarr/subscriptions","organizations_url":"https://api.github.com/users/chwarr/orgs","repos_url":"https://api.github.com/users/chwarr/repos","events_url":"https://api.github.com/users/chwarr/events{/privacy}","received_events_url":"https://api.github.com/users/chwarr/received_events","type":"User","site_admin":false},"repo":{"id":30380978,"name":"bond","full_name":"chwarr/bond","owner":{"login":"chwarr","id":10605667,"avatar_url":"https://avatars3.githubusercontent.com/u/10605667?v=4","gravatar_id":"","url":"https://api.github.com/users/chwarr","html_url":"https://github.com/chwarr","followers_url":"https://api.github.com/users/chwarr/followers","following_url":"https://api.github.com/users/chwarr/following{/other_user}","gists_url":"https://api.github.com/users/chwarr/gists{/gist_id}","starred_url":"https://api.github.com/users/chwarr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chwarr/subscriptions","organizations_url":"https://api.github.com/users/chwarr/orgs","repos_url":"https://api.github.com/users/chwarr/repos","events_url":"https://api.github.com/users/chwarr/events{/privacy}","received_events_url":"https://api.github.com/users/chwarr/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/chwarr/bond","description":"Bond is a cross-platform framework for working with schematized data. It supports cross-language de/serialization and powerful generic mechanisms for efficiently manipulating data. Bond is broadly used at Microsoft in high scale services. ","fork":true,"url":"https://api.github.com/repos/chwarr/bond","forks_url":"https://api.github.com/repos/chwarr/bond/forks","keys_url":"https://api.github.com/repos/chwarr/bond/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chwarr/bond/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chwarr/bond/teams","hooks_url":"https://api.github.com/repos/chwarr/bond/hooks","issue_events_url":"https://api.github.com/repos/chwarr/bond/issues/events{/number}","events_url":"https://api.github.com/repos/chwarr/bond/events","assignees_url":"https://api.github.com/repos/chwarr/bond/assignees{/user}","branches_url":"https://api.github.com/repos/chwarr/bond/branches{/branch}","tags_url":"https://api.github.com/repos/chwarr/bond/tags","blobs_url":"https://api.github.com/repos/chwarr/bond/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chwarr/bond/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chwarr/bond/git/refs{/sha}","trees_url":"https://api.github.com/repos/chwarr/bond/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chwarr/bond/statuses/{sha}","languages_url":"https://api.github.com/repos/chwarr/bond/languages","stargazers_url":"https://api.github.com/repos/chwarr/bond/stargazers","contributors_url":"https://api.github.com/repos/chwarr/bond/contributors","subscribers_url":"https://api.github.com/repos/chwarr/bond/subscribers","subscription_url":"https://api.github.com/repos/chwarr/bond/subscription","commits_url":"https://api.github.com/repos/chwarr/bond/commits{/sha}","git_commits_url":"https://api.github.com/repos/chwarr/bond/git/commits{/sha}","comments_url":"https://api.github.com/repos/chwarr/bond/comments{/number}","issue_comment_url":"https://api.github.com/repos/chwarr/bond/issues/comments{/number}","contents_url":"https://api.github.com/repos/chwarr/bond/contents/{+path}","compare_url":"https://api.github.com/repos/chwarr/bond/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chwarr/bond/merges","archive_url":"https://api.github.com/repos/chwarr/bond/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chwarr/bond/downloads","issues_url":"https://api.github.com/repos/chwarr/bond/issues{/number}","pulls_url":"https://api.github.com/repos/chwarr/bond/pulls{/number}","milestones_url":"https://api.github.com/repos/chwarr/bond/milestones{/number}","notifications_url":"https://api.github.com/repos/chwarr/bond/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chwarr/bond/labels{/name}","releases_url":"https://api.github.com/repos/chwarr/bond/releases{/id}","deployments_url":"https://api.github.com/repos/chwarr/bond/deployments","created_at":"2015-02-05T22:05:22Z","updated_at":"2018-04-06T23:54:41Z","pushed_at":"2018-04-12T23:20:17Z","git_url":"git://github.com/chwarr/bond.git","ssh_url":"git@github.com:chwarr/bond.git","clone_url":"https://github.com/chwarr/bond.git","svn_url":"https://github.com/chwarr/bond","homepage":null,"size":6778,"stargazers_count":2,"watchers_count":2,"language":"C++","has_issues":false,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":0,"watchers":2,"default_branch":"master"}},"base":{"label":"Microsoft:master","ref":"master","sha":"a256dbc3191471be822bdbe35257c263de6a8941","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars2.githubusercontent.com/u/6154722?v=4","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":28014525,"name":"bond","full_name":"Microsoft/bond","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars2.githubusercontent.com/u/6154722?v=4","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/bond","description":"Bond is a cross-platform framework for working with schematized data. It supports cross-language de/serialization and powerful generic mechanisms for efficiently manipulating data. Bond is broadly used at Microsoft in high scale services. ","fork":false,"url":"https://api.github.com/repos/Microsoft/bond","forks_url":"https://api.github.com/repos/Microsoft/bond/forks","keys_url":"https://api.github.com/repos/Microsoft/bond/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/bond/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/bond/teams","hooks_url":"https://api.github.com/repos/Microsoft/bond/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/bond/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/bond/events","assignees_url":"https://api.github.com/repos/Microsoft/bond/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/bond/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/bond/tags","blobs_url":"https://api.github.com/repos/Microsoft/bond/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/bond/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/bond/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/bond/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/bond/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/bond/languages","stargazers_url":"https://api.github.com/repos/Microsoft/bond/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/bond/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/bond/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/bond/subscription","commits_url":"https://api.github.com/repos/Microsoft/bond/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/bond/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/bond/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/bond/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/bond/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/bond/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/bond/merges","archive_url":"https://api.github.com/repos/Microsoft/bond/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/bond/downloads","issues_url":"https://api.github.com/repos/Microsoft/bond/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/bond/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/bond/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/bond/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/bond/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/bond/releases{/id}","deployments_url":"https://api.github.com/repos/Microsoft/bond/deployments","created_at":"2014-12-15T01:05:31Z","updated_at":"2018-04-10T16:57:51Z","pushed_at":"2018-04-12T23:20:18Z","git_url":"git://github.com/Microsoft/bond.git","ssh_url":"git@github.com:Microsoft/bond.git","clone_url":"https://github.com/Microsoft/bond.git","svn_url":"https://github.com/Microsoft/bond","homepage":null,"size":12967,"stargazers_count":1707,"watchers_count":1707,"language":"C++","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":234,"mirror_url":null,"archived":false,"open_issues_count":123,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":234,"open_issues":123,"watchers":1707,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/bond/pulls/849"},"html":{"href":"https://github.com/Microsoft/bond/pull/849"},"issue":{"href":"https://api.github.com/repos/Microsoft/bond/issues/849"},"comments":{"href":"https://api.github.com/repos/Microsoft/bond/issues/849/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/bond/pulls/849/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/bond/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/bond/pulls/849/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/bond/statuses/ae16537be074fbc10a578e03400dfc8623f15be9"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"ara-ayvazyan"}}