From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <3MGQzYggKCt0FOQNBHC9FNNFKD.BNLKHA9AHF9HKRNTQBDV9QD.NQF@flex--gprocida.bounces.google.com> Received: from mail-ed1-x549.google.com (mail-ed1-x549.google.com [IPv6:2a00:1450:4864:20::549]) by sourceware.org (Postfix) with ESMTPS id 730D4388451E for ; Thu, 17 Mar 2022 16:39:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 730D4388451E Received: by mail-ed1-x549.google.com with SMTP id da28-20020a056402177c00b00415ce4b20baso3430889edb.17 for ; Thu, 17 Mar 2022 09:39:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=NKbddToFD1QcmBdPRTG0aRcudo0hmqfb5JZbFLp04N4=; b=mzXDWnFnJSkg27dh/75YT1g/MXsB1EgjG8T3peUZ9v3kT9EYlVcbgY0sRigp4S1VNK J+1CmK7KPOntVp+3QgrBA1ljEUw0GSIrsTfRYaXrSA8B/N2OaM5JJc8NIR+BVS+ReaAw 2BPIcJKhURC3OYwAswSwFENLuHy7WUOPrncoV5t9bUDFLFkOY/Gr78/cvTxk/t1SX0z2 unXhmQJj2MLuII1dpEwPRislfYMea0XYcsn7YLmc1yRaQY5yjZnQystB0BE387bEFMiM TJpJJOsUeIFvYZeWxMTZu5BtOK0hSx8NxSJjo81b3oZpEqRtp89iSReGVqSVo6SRq9FL FQTA== X-Gm-Message-State: AOAM533X761WBiUeQU9qiiBJ0vMWsk89owym9hrFZU/xIS2UQzv7PH5Y jmiAU9BjYwpvFujGvXOMTwJkJNG4QAywiI5OYyUxS0x9Q1O3cIQhawd962LFYgx/ovVt7VAHjjM kjRqYQAWivgUYL2AtA40XsYc0OyQTlqPt9YHSCJvBy/y2gHFat+hvdURMKfvEPIbiaBvkZIc= X-Google-Smtp-Source: ABdhPJzh/1wNMBGS9RCsfHrf7hfyiWoTBBMqo2FjUnf9LQ6mh4ChiGOk8LIerXXDUTujfS5sYkF3dS3jwfE2cA== X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:210:cfc0:be7d:c8f5:f085]) (user=gprocida job=sendgmr) by 2002:a17:906:9741:b0:6da:c274:6b18 with SMTP id o1-20020a170906974100b006dac2746b18mr5186034ejy.207.1647535152880; Thu, 17 Mar 2022 09:39:12 -0700 (PDT) Date: Thu, 17 Mar 2022 16:38:56 +0000 In-Reply-To: <20220317163858.353762-1-gprocida@google.com> Message-Id: <20220317163858.353762-3-gprocida@google.com> Mime-Version: 1.0 References: <20220316163055.4127796-1-gprocida@google.com> <20220317163858.353762-1-gprocida@google.com> X-Mailer: git-send-email 2.35.1.894.gb6a874cedc-goog Subject: [PATCH v3 2/4] optional: minor improvements From: Giuliano Procida To: libabigail@sourceware.org Cc: dodji@seketeli.org, kernel-team@android.com, gprocida@google.com, maennich@google.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-21.5 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Mar 2022 16:39:19 -0000 This change makes minor improvements to the optional class used with pre-C++17 compilers. - adds operator== and operator!= - adds various missing noexcept (but not constexpr) decorations - defines operator bool in terms of has_value Note that some constexpr decorations would require C++17 anyway. * include/abg-cxx-compat.h (optional): Add operator== and operator!=. Add noexcept decorations. Tweak operator bool. Reviewed-by: Matthias Maennich Signed-off-by: Giuliano Procida --- include/abg-cxx-compat.h | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/include/abg-cxx-compat.h b/include/abg-cxx-compat.h index 443905c7..5c5943d0 100644 --- a/include/abg-cxx-compat.h +++ b/include/abg-cxx-compat.h @@ -45,7 +45,7 @@ public: optional(const T& value) : has_value_(true), value_(value) {} bool - has_value() const + has_value() const noexcept { return has_value_; } @@ -67,19 +67,19 @@ public: } const T& - operator*() const + operator*() const& noexcept { return value_; } T& - operator*() + operator*() & noexcept { return value_; } const T* - operator->() const + operator->() const noexcept { return &value_; } T* - operator->() + operator->() noexcept { return &value_; } optional& @@ -90,9 +90,27 @@ public: return *this; } - explicit operator bool() const { return has_value_; } + explicit operator bool() const noexcept { return has_value(); } }; +template +bool +operator==(const optional& lhs, const optional& rhs) +{ + if (!lhs.has_value() && !rhs.has_value()) + return true; + if (!lhs.has_value() || !rhs.has_value()) + return false; + return lhs.value() == rhs.value(); +} + +template +bool +operator!=(const optional& lhs, const optional& rhs) +{ + return !(lhs == rhs); +} + #endif } -- 2.35.1.894.gb6a874cedc-goog