From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30659 invoked by alias); 4 Nov 2016 03:23:07 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 30108 invoked by uid 89); 4 Nov 2016 03:22:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=6812, 68,12, yyyy-mm-dd, yyyymmdd X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 04 Nov 2016 03:22:22 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E95DE83F43 for ; Fri, 4 Nov 2016 03:22:20 +0000 (UTC) Received: from cascais.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uA43MJAD017578 for ; Thu, 3 Nov 2016 23:22:20 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 1/3] enum_flags: Use C++11 std::underlying_type Date: Fri, 04 Nov 2016 03:23:00 -0000 Message-Id: <1478229738-24469-2-git-send-email-palves@redhat.com> In-Reply-To: <1478229738-24469-1-git-send-email-palves@redhat.com> References: <1478229738-24469-1-git-send-email-palves@redhat.com> X-SW-Source: 2016-11/txt/msg00081.txt.bz2 Now that we can require C++11, we can use std::underlying_type instead of rolling our own. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * common/enum-flags.h: Include . (integer_for_size, enum_underlying_type): Delete. (class enum_flags): Use std::underlying_type. --- gdb/common/enum-flags.h | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/gdb/common/enum-flags.h b/gdb/common/enum-flags.h index 9b8c952..ff48067 100644 --- a/gdb/common/enum-flags.h +++ b/gdb/common/enum-flags.h @@ -51,6 +51,8 @@ #ifdef __cplusplus +#include + /* Traits type used to prevent the global operator overloads from instantiating for non-flag enums. */ template struct enum_flags_type {}; @@ -66,32 +68,12 @@ template struct enum_flags_type {}; typedef enum_flags type; \ } -/* Until we can rely on std::underlying type being universally - available (C++11), roll our own for enums. */ -template class integer_for_size { typedef void type; }; -template<> struct integer_for_size<1, 0> { typedef uint8_t type; }; -template<> struct integer_for_size<2, 0> { typedef uint16_t type; }; -template<> struct integer_for_size<4, 0> { typedef uint32_t type; }; -template<> struct integer_for_size<8, 0> { typedef uint64_t type; }; -template<> struct integer_for_size<1, 1> { typedef int8_t type; }; -template<> struct integer_for_size<2, 1> { typedef int16_t type; }; -template<> struct integer_for_size<4, 1> { typedef int32_t type; }; -template<> struct integer_for_size<8, 1> { typedef int64_t type; }; - -template -struct enum_underlying_type -{ - typedef typename - integer_for_size(T (-1) < T (0))>::type - type; -}; - template class enum_flags { public: typedef E enum_type; - typedef typename enum_underlying_type::type underlying_type; + typedef typename std::underlying_type::type underlying_type; private: /* Private type used to support initializing flag types with zero: -- 2.5.5