VirtualBox

Changeset 49572 in vbox


Ignore:
Timestamp:
Nov 20, 2013 9:59:42 AM (11 years ago)
Author:
vboxsync
Message:

com/array.h: Use type traits to support signed and unsigned types in API bindings (only GCC >= 4.6 or MSVC >= 16.0).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/com/array.h

    r47848 r49572  
    44
    55/*
    6  * Copyright (C) 2006-2012 Oracle Corporation
     6 * Copyright (C) 2006-2013 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    164164#endif
    165165
     166        /* Type traits are a C++ 11 feature, so not available everywhere (yet). */
     167        /* Only GCC 4.6 or newer. */
     168#if    (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 406) \
     169       /* Only MSVC++ 10.0 (Visual Studio 2010) or newer. */           \
     170    || (defined(_MSC_VER) && (_MSC_VER >= 1600))
     171    #define VBOX_WITH_TYPE_TRAITS
     172#endif
     173
     174#ifdef VBOX_WITH_TYPE_TRAITS
     175# include <type_traits>
     176#endif
     177
    166178#include "VBox/com/defs.h"
    167179#include "VBox/com/ptr.h"
     
    394406    static VARTYPE VarType()
    395407    {
     408#ifdef VBOX_WITH_TYPE_TRAITS
     409        if (    std::is_integral<T>::value
     410            && !std::is_signed<T>::value)
     411        {
     412            if (sizeof(T) % 8 == 0) return VT_UI8;
     413            if (sizeof(T) % 4 == 0) return VT_UI4;
     414            if (sizeof(T) % 2 == 0) return VT_UI2;
     415            return VT_UI1;
     416        }
     417#endif
    396418        if (sizeof(T) % 8 == 0) return VT_I8;
    397419        if (sizeof(T) % 4 == 0) return VT_I4;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette