- Joined
- 3/24/08
- Messages
- 63
- Points
- 18
Dunno if this is the right forum, but the question sprung into existence as a direct consequence of HW #1, so perhaps this is the right venue for a programmy type question.
"using namespace std;" brings in all kinds of stuff into the global namespace, ranging from file readers to iterators, to newline characters to vectors to bessel functions.
When using the Boost library, using the std namespace will make vector declarations ambiguous, since we have:
std::vector
boost::numeric::ublas::vector;
It's not really a big deal at all, since a using directive (or explicit reference) makes things unambiguous:
I'm guaranteed that v is a "Basic Linear Algebra Subprograms" vector, and not a "Standard Template Library" vector. But this is inelegant.
Namespaces in C++ can be nested. I was wondering if the std namespace was partitioned any finer than on the ... whole universe level. For numerical calculations we're mostly interested in cin, cout, and endl to interact with our programs. So I'm wondering if there's something like:
using namespace std::consoleIOstuff;
which would bring cin, cout, endl into the global namespace, but leave things like std::vector and gudermanian functions out of the global namespace. Spent 10 minutes Googling, but couldn't find any such thing.
Implicit to all this is my desire to not be bothered with typing
using std::foo;
using std::bar;
using std::foobar;
using std::barfoo;
in all my programs. I really just want one clean declaration that imports all IO related stuff into the global namespace, and nothing else.
"using namespace std;" brings in all kinds of stuff into the global namespace, ranging from file readers to iterators, to newline characters to vectors to bessel functions.
When using the Boost library, using the std namespace will make vector declarations ambiguous, since we have:
std::vector
boost::numeric::ublas::vector;
It's not really a big deal at all, since a using directive (or explicit reference) makes things unambiguous:
Code:
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
using namespace boost::numeric::ublas;
using namespace std;
int main ( void )
{
using boost::numeric::ublas::vector; // Use Boost's vector, not STL's.
vector<complex<double> > v(3);
. . .
Namespaces in C++ can be nested. I was wondering if the std namespace was partitioned any finer than on the ... whole universe level. For numerical calculations we're mostly interested in cin, cout, and endl to interact with our programs. So I'm wondering if there's something like:
using namespace std::consoleIOstuff;
which would bring cin, cout, endl into the global namespace, but leave things like std::vector and gudermanian functions out of the global namespace. Spent 10 minutes Googling, but couldn't find any such thing.
Implicit to all this is my desire to not be bothered with typing
using std::foo;
using std::bar;
using std::foobar;
using std::barfoo;
in all my programs. I really just want one clean declaration that imports all IO related stuff into the global namespace, and nothing else.