utils: fix build error with g++
[project/libubox.git] / avl.h
diff --git a/avl.h b/avl.h
index e4ca7d8..1eb18ad 100644 (file)
--- a/avl.h
+++ b/avl.h
@@ -153,6 +153,18 @@ enum avl_find_mode {
   AVL_FIND_GREATEREQUAL
 };
 
   AVL_FIND_GREATEREQUAL
 };
 
+#define AVL_TREE_INIT(_name, _comp, _allow_dups, _cmp_ptr)     \
+       {                                                       \
+               .list_head = LIST_HEAD_INIT(_name.list_head),   \
+               .comp = _comp,                                  \
+               .allow_dups = _allow_dups,                      \
+               .cmp_ptr = _cmp_ptr                             \
+       }
+
+#define AVL_TREE(_name, _comp, _allow_dups, _cmp_ptr)          \
+       struct avl_tree _name =                                 \
+               AVL_TREE_INIT(_name, _comp, _allow_dups, _cmp_ptr)
+
 void EXPORT(avl_init)(struct avl_tree *, avl_tree_comp, bool, void *);
 struct avl_node *EXPORT(avl_find)(const struct avl_tree *, const void *);
 struct avl_node *EXPORT(avl_find_greaterequal)(const struct avl_tree *tree, const void *key);
 void EXPORT(avl_init)(struct avl_tree *, avl_tree_comp, bool, void *);
 struct avl_node *EXPORT(avl_find)(const struct avl_tree *, const void *);
 struct avl_node *EXPORT(avl_find_greaterequal)(const struct avl_tree *tree, const void *key);
@@ -226,7 +238,7 @@ __avl_find_element(const struct avl_tree *tree, const void *key, size_t offset,
  *    NULL if no element was found
  */
 #define avl_find_element(tree, key, element, node_element) \
  *    NULL if no element was found
  */
 #define avl_find_element(tree, key, element, node_element) \
-  ((typeof(*(element)) *)__avl_find_element(tree, key, offsetof(typeof(*(element)), node_element), AVL_FIND_EQUAL))
+  ((__typeof__(*(element)) *)__avl_find_element(tree, key, offsetof(typeof(*(element)), node_element), AVL_FIND_EQUAL))
 
 /**
  * @param tree pointer to avl-tree
 
 /**
  * @param tree pointer to avl-tree
@@ -239,7 +251,7 @@ __avl_find_element(const struct avl_tree *tree, const void *key, size_t offset,
  *    NULL if no element was found
  */
 #define avl_find_le_element(tree, key, element, node_element) \
  *    NULL if no element was found
  */
 #define avl_find_le_element(tree, key, element, node_element) \
-  ((typeof(*(element)) *)__avl_find_element(tree, key, offsetof(typeof(*(element)), node_element), AVL_FIND_LESSEQUAL))
+  ((__typeof__(*(element)) *)__avl_find_element(tree, key, offsetof(typeof(*(element)), node_element), AVL_FIND_LESSEQUAL))
 
 /**
  * @param tree pointer to avl-tree
 
 /**
  * @param tree pointer to avl-tree
@@ -252,7 +264,7 @@ __avl_find_element(const struct avl_tree *tree, const void *key, size_t offset,
  *    NULL if no element was found
  */
 #define avl_find_ge_element(tree, key, element, node_element) \
  *    NULL if no element was found
  */
 #define avl_find_ge_element(tree, key, element, node_element) \
-  ((typeof(*(element)) *)__avl_find_element(tree, key, offsetof(typeof(*(element)), node_element), AVL_FIND_GREATEREQUAL))
+  ((__typeof__(*(element)) *)__avl_find_element(tree, key, offsetof(typeof(*(element)), node_element), AVL_FIND_GREATEREQUAL))
 
 /**
  * This function must not be called for an empty tree
 
 /**
  * This function must not be called for an empty tree
@@ -266,7 +278,7 @@ __avl_find_element(const struct avl_tree *tree, const void *key, size_t offset,
  *    (automatically converted to type 'element')
  */
 #define avl_first_element(tree, element, node_member) \
  *    (automatically converted to type 'element')
  */
 #define avl_first_element(tree, element, node_member) \
-  container_of((tree)->list_head.next, typeof(*(element)), node_member.list)
+  container_of((tree)->list_head.next, __typeof__(*(element)), node_member.list)
 
 /**
  * @param tree pointer to tree
 
 /**
  * @param tree pointer to tree
@@ -278,7 +290,7 @@ __avl_find_element(const struct avl_tree *tree, const void *key, size_t offset,
  *    (automatically converted to type 'element')
  */
 #define avl_last_element(tree, element, node_member) \
  *    (automatically converted to type 'element')
  */
 #define avl_last_element(tree, element, node_member) \
-  container_of((tree)->list_head.prev, typeof(*(element)), node_member.list)
+  container_of((tree)->list_head.prev, __typeof__(*(element)), node_member.list)
 
 /**
  * This function must not be called for the last element of
 
 /**
  * This function must not be called for the last element of
@@ -291,7 +303,7 @@ __avl_find_element(const struct avl_tree *tree, const void *key, size_t offset,
  *    (automatically converted to type 'element')
  */
 #define avl_next_element(element, node_member) \
  *    (automatically converted to type 'element')
  */
 #define avl_next_element(element, node_member) \
-  container_of((&(element)->node_member.list)->next, typeof(*(element)), node_member.list)
+  container_of((&(element)->node_member.list)->next, __typeof__(*(element)), node_member.list)
 
 /**
  * This function must not be called for the first element of
 
 /**
  * This function must not be called for the first element of
@@ -304,7 +316,7 @@ __avl_find_element(const struct avl_tree *tree, const void *key, size_t offset,
  *    (automatically converted to type 'element')
  */
 #define avl_prev_element(element, node_member) \
  *    (automatically converted to type 'element')
  */
 #define avl_prev_element(element, node_member) \
-  container_of((&(element)->node_member.list)->prev, typeof(*(element)), node_member.list)
+  container_of((&(element)->node_member.list)->prev, __typeof__(*(element)), node_member.list)
 
 /**
  * Loop over a block of elements of a tree, used similar to a for() command.
 
 /**
  * Loop over a block of elements of a tree, used similar to a for() command.