N
Nate Barney
Is it acceptable, according to the standard, to make the type of a
template parameter a dependent type of a previous template parameter in
the same template declaration?
I tried this on a lark, just to see what would happen. To my surprise,
it compiled and ran correctly under g++ 4.1.1.
#include <iostream>
#include <iterator>
template <typename It
typename std::iterator_traits<It>::difference_type N>
void print(It it)
{
for (int i = 0; i < N; ++i)
std::cout << *it++ << std::endl;
}
int main()
{
int a[] = { 0, 1, 2, 3, 4 };
print<const int*,5>(a);
}
template parameter a dependent type of a previous template parameter in
the same template declaration?
I tried this on a lark, just to see what would happen. To my surprise,
it compiled and ran correctly under g++ 4.1.1.
#include <iostream>
#include <iterator>
template <typename It
typename std::iterator_traits<It>::difference_type N>
void print(It it)
{
for (int i = 0; i < N; ++i)
std::cout << *it++ << std::endl;
}
int main()
{
int a[] = { 0, 1, 2, 3, 4 };
print<const int*,5>(a);
}