Commit ccd10f94 authored by Philip Chimento's avatar Philip Chimento 🚮

maint: Use concise C++17 type traits

Now that we have C++17, we can make these a bit more readable.
parent ff05be33
......@@ -193,13 +193,11 @@ GJS_USE inline gboolean gjs_arg_get<gboolean, GI_TYPE_TAG_BOOLEAN>(
}
template <typename T, GITypeTag TAG = GI_TYPE_TAG_VOID>
inline std::enable_if_t<!std::is_pointer<T>::value> gjs_arg_unset(
GIArgument* arg) {
inline std::enable_if_t<!std::is_pointer_v<T>> gjs_arg_unset(GIArgument* arg) {
gjs_arg_set<T, TAG>(arg, static_cast<T>(0));
}
template <typename T, GITypeTag TAG = GI_TYPE_TAG_VOID>
inline std::enable_if_t<std::is_pointer<T>::value> gjs_arg_unset(
GIArgument* arg) {
inline std::enable_if_t<std::is_pointer_v<T>> gjs_arg_unset(GIArgument* arg) {
gjs_arg_set<T, TAG>(arg, nullptr);
}
......@@ -480,14 +480,14 @@ create_hash_table_for_key_type(GITypeInfo *key_param_info)
template <typename T>
GJS_JSAPI_RETURN_CONVENTION static inline std::enable_if_t<
std::is_integral<T>::value && std::is_signed<T>::value, bool>
std::is_integral_v<T> && std::is_signed_v<T>, bool>
js_value_convert(JSContext* cx, const JS::HandleValue& value, T* out) {
return JS::ToInt32(cx, value, out);
}
template <typename T>
GJS_JSAPI_RETURN_CONVENTION static inline std::enable_if_t<
std::is_integral<T>::value && std::is_unsigned<T>::value, bool>
std::is_integral_v<T> && std::is_unsigned_v<T>, bool>
js_value_convert(JSContext* cx, const JS::HandleValue& value, T* out) {
return JS::ToUint32(cx, value, out);
}
......@@ -498,7 +498,7 @@ GJS_JSAPI_RETURN_CONVENTION static bool hashtable_int_key(
void** pointer_out) {
Container i;
static_assert(std::is_integral<IntType>::value, "Need an integer");
static_assert(std::is_integral_v<IntType>, "Need an integer");
static_assert(std::numeric_limits<Container>::max() >=
std::numeric_limits<IntType>::max(),
"Max possible Container value must be at least the max possible IntType value");
......@@ -525,7 +525,7 @@ GJS_JSAPI_RETURN_CONVENTION static bool hashtable_int_key(
template <typename IntType>
GJS_JSAPI_RETURN_CONVENTION static inline std::enable_if_t<
std::is_signed<IntType>::value, bool>
std::is_signed_v<IntType>, bool>
hashtable_int_key(JSContext* cx, const JS::HandleValue& value,
bool* out_of_range, void** pointer_out) {
return hashtable_int_key<IntType, int32_t>(cx, value, out_of_range,
......@@ -534,7 +534,7 @@ hashtable_int_key(JSContext* cx, const JS::HandleValue& value,
template <typename IntType>
GJS_JSAPI_RETURN_CONVENTION static inline std::enable_if_t<
std::is_unsigned<IntType>::value, bool>
std::is_unsigned_v<IntType>, bool>
hashtable_int_key(JSContext* cx, const JS::HandleValue& value,
bool* out_of_range, void** pointer_out) {
return hashtable_int_key<IntType, uint32_t>(cx, value, out_of_range,
......
......@@ -35,7 +35,6 @@
#include <glib-object.h>
#include <glib.h>
#include <js/AllocPolicy.h>
#include <js/GCHashTable.h>
#include <js/GCVector.h>
#include <js/Promise.h>
......@@ -54,6 +53,9 @@ namespace mozilla {
template <class Key>
struct DefaultHasher;
}
namespace js {
class SystemAllocPolicy;
}
class GjsAtoms;
class JSTracer;
......@@ -70,7 +72,7 @@ using GTypeTable =
struct Dummy {};
using GTypeNotUint64 =
std::conditional_t<!std::is_same<GType, uint64_t>::value, GType, Dummy>;
std::conditional_t<!std::is_same_v<GType, uint64_t>, GType, Dummy>;
// The GC sweep method should ignore FundamentalTable and GTypeTable's key types
namespace JS {
......
......@@ -33,8 +33,6 @@
#include <stdint.h>
#include <type_traits> // for is_same
#include "gjs/macros.h"
enum class GjsGlobalType {
......@@ -95,18 +93,18 @@ JS::Value get_global_slot(JSObject* global, uint32_t slot);
template <typename Slot>
inline void gjs_set_global_slot(JSObject* global, Slot slot, JS::Value value) {
static_assert(std::is_same<GjsBaseGlobalSlot, Slot>::value ||
std::is_same<GjsGlobalSlot, Slot>::value ||
std::is_same<GjsDebuggerGlobalSlot, Slot>::value,
static_assert(std::is_same_v<GjsBaseGlobalSlot, Slot> ||
std::is_same_v<GjsGlobalSlot, Slot> ||
std::is_same_v<GjsDebuggerGlobalSlot, Slot>,
"Must use a GJS global slot enum");
detail::set_global_slot(global, static_cast<uint32_t>(slot), value);
}
template <typename Slot>
inline JS::Value gjs_get_global_slot(JSObject* global, Slot slot) {
static_assert(std::is_same<GjsBaseGlobalSlot, Slot>::value ||
std::is_same<GjsGlobalSlot, Slot>::value ||
std::is_same<GjsDebuggerGlobalSlot, Slot>::value,
static_assert(std::is_same_v<GjsBaseGlobalSlot, Slot> ||
std::is_same_v<GjsGlobalSlot, Slot> ||
std::is_same_v<GjsDebuggerGlobalSlot, Slot>,
"Must use a GJS global slot enum");
return detail::get_global_slot(global, static_cast<uint32_t>(slot));
}
......
......@@ -189,16 +189,10 @@ assign(JSContext *cx,
/* Special case: treat pointer-to-enum as pointer-to-int, but use enable_if to
* prevent instantiation for any other types besides pointer-to-enum */
template<typename T,
typename std::enable_if<std::is_enum<T>::value, int>::type = 0>
GJS_ALWAYS_INLINE
static inline void
assign(JSContext *cx,
char c,
bool nullable,
JS::HandleValue value,
T *ref)
{
template <typename T, typename std::enable_if_t<std::is_enum_v<T>, int> = 0>
GJS_ALWAYS_INLINE static inline void assign(JSContext* cx, char c,
bool nullable,
JS::HandleValue value, T* ref) {
/* Sadly, we cannot use std::underlying_type<T> here; the underlying type of
* an enum is implementation-defined, so it would not be clear what letter
* to use in the format string. For the same reason, we can only support
......@@ -212,9 +206,8 @@ assign(JSContext *cx,
/* Force JS::RootedObject * to be converted to JS::MutableHandleObject,
* see overload in jsapi-util-args.cpp */
template <typename T,
typename std::enable_if<!std::is_same<T, JS::RootedObject*>::value,
int>::type = 0>
template <typename T, typename std::enable_if_t<
!std::is_same_v<T, JS::RootedObject*>, int> = 0>
static inline void free_if_necessary(T param_ref G_GNUC_UNUSED) {}
GJS_ALWAYS_INLINE
......
......@@ -204,7 +204,7 @@ class GjsMaybeOwned {
/* Use debug_addr() only for debug logging, because it is unbarriered. */
template <typename U = T>
GJS_USE const void* debug_addr(
std::enable_if_t<std::is_pointer<U>::value>* = nullptr) const {
std::enable_if_t<std::is_pointer_v<U>>* = nullptr) const {
return m_root ? m_root->get() : m_heap.unbarrieredGet();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment