From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by sourceware.org (Postfix) with ESMTPS id 8C201386101D for ; Thu, 20 Aug 2020 16:00:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8C201386101D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=alves.ped@gmail.com Received: by mail-wm1-f66.google.com with SMTP id g75so2050083wme.4 for ; Thu, 20 Aug 2020 09:00:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=5MUW2VC2EcjwgijXPHJU62C58JKJPWsKg3m45ol9CJg=; b=XNvMNLcy1/lfXT7FlDAkfe1g5b6syiN0E31OvraWf+vdNuyJ2WNepyt7/U5n00qB8H Mh68Rj0So6pjmwVbEdwQn1FRBxhZHthI4C6tgZo9WWU2vCcL6sofjQD58FKdVVwutSIA WsVEGTGQ0lMCuBHBJhMUK8IsNqO8CY/dsHyhCYv2lZegxrkJ9T3mb+ONXSHzg7xECXI/ 8YfuoYOZDM0nqRfC86vN4p/unEVxO1TatKj1nq2N2QW8KxtZnmJb2ypVMeXhVsU4EI1y UzmoyNZhjen3vqm9OvzioxhS93vddgUMEb7awFT+HHLL1+Ts/dXawU5mWVrcy0cHYZKW QNVg== X-Gm-Message-State: AOAM532/SH22IlWWnLYXQ4wakFNyDuiZLWLCUZbTuYLl5YMNxs4Cgzlb K27itymAnPQJ3CUZAR+/knvLgjR7O/k/RQ== X-Google-Smtp-Source: ABdhPJw4PaFqWsdzzMjFu+LY7gYHkmmMhQSB7ifdclgpxZZXzDYZrWM1QWT92/mh8foAK+XfTTVQog== X-Received: by 2002:a05:600c:2184:: with SMTP id e4mr4045155wme.24.1597939244586; Thu, 20 Aug 2020 09:00:44 -0700 (PDT) Received: from ?IPv6:2001:8a0:f905:5600:56ee:75ff:fe8d:232b? ([2001:8a0:f905:5600:56ee:75ff:fe8d:232b]) by smtp.gmail.com with ESMTPSA id a188sm5325675wmc.31.2020.08.20.09.00.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Aug 2020 09:00:43 -0700 (PDT) Subject: Re: [PATCH 1/8] gdbsupport: Provide global operators |=, &=, and ^= for enum bit flags To: Andrew Burgess , Tom Tromey References: <8eb7f409ca572c526de08ab23878be905f5fef42.1597319264.git.andrew.burgess@embecosm.com> <87a6yvhls1.fsf@tromey.com> <20200817104034.GJ853475@embecosm.com> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: <3516d9ac-73fd-39e2-bd7d-986595e1c3f3@palves.net> Date: Thu, 20 Aug 2020 17:00:42 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20200817104034.GJ853475@embecosm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Aug 2020 16:00:48 -0000 On 8/17/20 11:40 AM, Andrew Burgess wrote: >> Andrew> The current enum bit flags mechanism provides global operators &, |, >> Andrew> ^, ~, but does not provide &=, |=, ^=. >> >> Andrew> The implementation for one of these, |=, would look like this: >> >> Andrew> template >> Andrew> typename enum_flags_type::type & >> Andrew> operator|= (enum_type &e1, enum_type e2) >> >> Why "enum_type &e1" and not "enum_flags_type::type &e1" >> here? The typename enum_flags_type::type in the return type is written that way instead of simply enum_flags & operator|= (enum_type &e1, enum_type e2) in order to have SFINAE disable the function if enum_flags_type is not defined for the flags type. I.e., that's what makes sure the function is only defined for enums we only want it defined for. There's no point in doing the SFINAE trick in both the return type and in the parameters.