| 1 | /* GLIB - Library of useful routines for C programming |
| 2 | * Copyright (C) 2021 Iain Lane, Xavier Claessens |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2.1 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
| 18 | #ifndef __GLIB_TYPEOF_H__ |
| 19 | #define __GLIB_TYPEOF_H__ |
| 20 | |
| 21 | #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION) |
| 22 | #error "Only <glib.h> can be included directly." |
| 23 | #endif |
| 24 | |
| 25 | #include <glib/gversionmacros.h> |
| 26 | |
| 27 | /* |
| 28 | * We can only use __typeof__ on GCC >= 4.8, and not when compiling C++. Since |
| 29 | * __typeof__ is used in a few places in GLib, provide a pre-processor symbol |
| 30 | * to factor the check out from callers. |
| 31 | * |
| 32 | * This symbol is private. |
| 33 | */ |
| 34 | #undef glib_typeof |
| 35 | #if !defined(__cplusplus) && (G_GNUC_CHECK_VERSION(4, 8) || defined(__clang__)) |
| 36 | #define glib_typeof(t) __typeof__ (t) |
| 37 | #elif defined(__cplusplus) && __cplusplus >= 201103L && GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_68 |
| 38 | /* C++11 decltype() is close enough for our usage */ |
| 39 | #include <type_traits> |
| 40 | #define glib_typeof(t) typename std::remove_reference<decltype (t)>::type |
| 41 | #endif |
| 42 | |
| 43 | #endif /* __GLIB_TYPEOF_H__ */ |
| 44 | |