R
robert.ferguson
Hi,
I am trying to improve the readability of my code. Currently, there
are many 'std::vector<>' statements of various types. I would like to
reduce this to 'vector<>'. Although I could use 'using namespace
std;', the vector type is the only time I use the standard library and
there are several other namespaces being used (mostly abstracted away
with typedef).
I think it would help the readability of my code if I could generalize
std::vector<> with something like:
'using std::vector as vector;'
Under my very basic test bed this chokes. I'm assuming this is because
vector requires a template. Is there an alternative to using 'using
namespace std;' if using typedef for the many possible template choices
is not preferrable?
Regards,
Rob
Test bed:
GNU C++ Version 3.32 (Apple Computer, Inc. build 1635)
Apple OS 10.3, PowerPC G5
Code example:
#include <vector>
int main()
{
using std::vector as vector; // chokes
vector<int> hi;
hi.push_back(1);
return 0;
}
Errors:
test.cpp:5: error: use of class template `template<class _Tp, class
_Alloc>
class std::vector' as expression
test.cpp:5: error: parse error before `;' token
I am trying to improve the readability of my code. Currently, there
are many 'std::vector<>' statements of various types. I would like to
reduce this to 'vector<>'. Although I could use 'using namespace
std;', the vector type is the only time I use the standard library and
there are several other namespaces being used (mostly abstracted away
with typedef).
I think it would help the readability of my code if I could generalize
std::vector<> with something like:
'using std::vector as vector;'
Under my very basic test bed this chokes. I'm assuming this is because
vector requires a template. Is there an alternative to using 'using
namespace std;' if using typedef for the many possible template choices
is not preferrable?
Regards,
Rob
Test bed:
GNU C++ Version 3.32 (Apple Computer, Inc. build 1635)
Apple OS 10.3, PowerPC G5
Code example:
#include <vector>
int main()
{
using std::vector as vector; // chokes
vector<int> hi;
hi.push_back(1);
return 0;
}
Errors:
test.cpp:5: error: use of class template `template<class _Tp, class
_Alloc>
class std::vector' as expression
test.cpp:5: error: parse error before `;' token