R
russ
Been looking at some code.....
#include <vector>
#include <iostream>
#include <algorithm>
template <typename T> struct A
{
struct B
{
std::vector< T > innervec;
} ;
std::vector< B > outervec;
};
template < typename T >
std:stream & operator<< ( std:stream & os, const typename A<T>::B &
b )
{
std::copy( b.innervec.begin(), b.innervec.end(),
std:stream_iterator<T>( os, "\t" ) );
return os;
}
template < typename T >
std:stream & operator<< ( std:stream & os, const A<T>& a )
{
typedef typename A<T>::B B_t;
std::copy( a.outervec.begin(), a.outervec.end(),
std:stream_iterator< B_t >( os, "\n" ) );
return os;
}
int main()
{
A<int> a;
A<int>::B b1;
A<int>::B b2;
b1.innervec.push_back( 11 );
b1.innervec.push_back( 12 );
b2.innervec.push_back( 21 );
b2.innervec.push_back( 22 );
a.outervec.push_back( b1 );
a.outervec.push_back( b2 );
std::cout << a;
}
Is that standard conforming?
Should it work fine as is?
My copy of MSVC 7.0 doesn't complain but Comeau's online beta says no
and fails when -tused is used.
If this is not supposed to work then why is that and what is the best
way of rewriting it?
#include <vector>
#include <iostream>
#include <algorithm>
template <typename T> struct A
{
struct B
{
std::vector< T > innervec;
} ;
std::vector< B > outervec;
};
template < typename T >
std:stream & operator<< ( std:stream & os, const typename A<T>::B &
b )
{
std::copy( b.innervec.begin(), b.innervec.end(),
std:stream_iterator<T>( os, "\t" ) );
return os;
}
template < typename T >
std:stream & operator<< ( std:stream & os, const A<T>& a )
{
typedef typename A<T>::B B_t;
std::copy( a.outervec.begin(), a.outervec.end(),
std:stream_iterator< B_t >( os, "\n" ) );
return os;
}
int main()
{
A<int> a;
A<int>::B b1;
A<int>::B b2;
b1.innervec.push_back( 11 );
b1.innervec.push_back( 12 );
b2.innervec.push_back( 21 );
b2.innervec.push_back( 22 );
a.outervec.push_back( b1 );
a.outervec.push_back( b2 );
std::cout << a;
}
Is that standard conforming?
Should it work fine as is?
My copy of MSVC 7.0 doesn't complain but Comeau's online beta says no
and fails when -tused is used.
If this is not supposed to work then why is that and what is the best
way of rewriting it?