X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/49e85177c669d793e84242983a1b1f430e47184e..2273aa3160195af3cb97e79827c696af31a4805f:/include/xbt/swag.h diff --git a/include/xbt/swag.h b/include/xbt/swag.h index df2bdfde4d..b153921393 100644 --- a/include/xbt/swag.h +++ b/include/xbt/swag.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2004-2014. The SimGrid Team. +/* Copyright (c) 2004-2015. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -149,11 +149,17 @@ static XBT_INLINE void *xbt_swag_getFirst(xbt_swag_t swag) * @param swag what to iterate over * @warning you cannot modify the \a swag while using this loop * @hideinitializer */ +#ifndef __cplusplus #define xbt_swag_foreach(obj,swag) \ for((obj)=xbt_swag_getFirst((swag)); \ (obj)!=NULL; \ (obj)=xbt_swag_getNext((obj),(swag)->offset)) - +#else +#define xbt_swag_foreach(obj,swag) \ + for((obj)=(decltype(obj)) xbt_swag_getFirst((swag)); \ + (obj)!=NULL; \ + (obj)=(decltype(obj)) xbt_swag_getNext((obj),(swag)->offset)) +#endif /** * @brief A safe swag iterator * @param obj the indice of the loop @@ -165,14 +171,30 @@ static XBT_INLINE void *xbt_swag_getFirst(xbt_swag_t swag) Well, safely... Err. You can remove \a obj without having any trouble at least. */ +#ifndef __cplusplus + #define xbt_swag_foreach_safe(obj,obj_next,swag) \ for((obj)=xbt_swag_getFirst((swag)), \ ((obj)?(obj_next=xbt_swag_getNext((obj),(swag)->offset)): \ - (obj_next=NULL)); \ + (obj_next=NULL)); \ (obj)!=NULL; \ (obj)=obj_next, \ ((obj)?(obj_next=xbt_swag_getNext((obj),(swag)->offset)): \ (obj_next=NULL)) ) + +#else + +#define xbt_swag_foreach_safe(obj,obj_next,swag) \ + for((obj) = (decltype(obj)) xbt_swag_getFirst((swag)), \ + ((obj)?(obj_next = (decltype(obj)) xbt_swag_getNext((obj),(swag)->offset)): \ + (obj_next=NULL)); \ + (obj) != NULL; \ + (obj) = obj_next, \ + ((obj)?(obj_next = (decltype(obj)) xbt_swag_getNext((obj),(swag)->offset)): \ + (obj_next=NULL)) ) + +#endif + /* @} */ SG_END_DECL()