[GCC-XML] template parm patch

Kyle Girard kyle at kdmanalytics.com
Tue Jan 26 10:36:25 EST 2010



> > Can you create a small use case, which shows when you got the error?
> > 

I ripped most of the following from QT's headers


#include <vector>
#include <iostream>

/* make use of typeof-extension */
template <typename T>
class QForeachContainer {
public:
    inline QForeachContainer(const T& t) : c(t), brk(0), i(c.begin()),
e(c.end()) { }
    const T c;
    int brk;
    typename T::const_iterator i, e;
};

#define Q_FOREACH(variable, container)                                \
for (QForeachContainer<__typeof__(container)> _container_(container); \
     !_container_.brk && _container_.i != _container_.e;              \
     __extension__  ({ ++_container_.brk; ++_container_.i; }))
\
    for (variable = *_container_.i;; __extension__ ({--_container_.brk;
break;}))

template<typename T>
void foo(std::vector<T> const & data)
{
  Q_FOREACH(const T & i, data)
    std::cout << i << std::endl;
}

int main()
{
  std::vector<int> v;
  v.push_back(1);
  foo(v);
  return 0;
}





More information about the gccxml mailing list