|
|
|
@ -10,21 +10,27 @@ These foreach macros are very non-standard and somewhat confusing, but I like th
|
|
|
|
|
|
|
|
|
|
#include "nvcore.h"
|
|
|
|
|
|
|
|
|
|
#if NV_CC_GNUC || NV_CC_CPP11 // If typeof or decltype is available:
|
|
|
|
|
#if NV_CC_GNUC // If typeof or decltype is available:
|
|
|
|
|
#if !NV_CC_CPP11
|
|
|
|
|
# define NV_DECLTYPE typeof // Using a non-standard extension over typeof that behaves as C++11 decltype
|
|
|
|
|
#else
|
|
|
|
|
# define NV_DECLTYPE decltype
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define NV_FOREACH(i, container) \
|
|
|
|
|
typedef NV_DECLTYPE(container) NV_STRING_JOIN2(cont,__LINE__); \
|
|
|
|
|
for(NV_STRING_JOIN2(cont,__LINE__)::PseudoIndex i((container).start()); !(container).isDone(i); (container).advance(i))
|
|
|
|
|
/*
|
|
|
|
|
Ideally we would like to write this:
|
|
|
|
|
|
|
|
|
|
#define NV_FOREACH(i, container) \
|
|
|
|
|
for(typename typeof(container)::PseudoIndex i((container).start()); !(container).isDone(i); (container).advance(i))
|
|
|
|
|
for(NV_DECLTYPE(container)::PseudoIndex i((container).start()); !(container).isDone(i); (container).advance(i))
|
|
|
|
|
|
|
|
|
|
But gcc versions prior to 4.7 required an intermediate type. See:
|
|
|
|
|
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=6709
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define NV_FOREACH(i, container) \
|
|
|
|
|
typedef NV_DECLTYPE(container) NV_STRING_JOIN2(cont,__LINE__); \
|
|
|
|
|
for(NV_STRING_JOIN2(cont,__LINE__)::PseudoIndex i((container).start()); !(container).isDone(i); (container).advance(i))
|
|
|
|
|
|
|
|
|
|
#else // If typeof not available:
|
|
|
|
|
|
|
|
|
|
#include <new> // placement new
|
|
|
|
|