Meh, it has two different purposes.
1) Import a specific type into the a namespace (ie use std::cout).
3) Create a type alias (ie template<typename T> using Vec = std::vector).
Printable View
Meh, it has two different purposes.
1) Import a specific type into the a namespace (ie use std::cout).
3) Create a type alias (ie template<typename T> using Vec = std::vector).
Into any namespace. You can do this:
This is quite often useful, e.g. many Boost libraries define most of their symbols in a library-specific namespace and lift a few important names into the boost namespace.Code:namespace foo { void x(); }
namespace bar { using foo::x; }
void f() { bar::x(); }
No, you do that using namespace:Quote:
2) Create a namespace alias (ie using l = boost::lambda).
Code:namespace ll = boost::lambda;
namespace fs = boost::filesystem;
That one is new in C++0x.Quote:
3) Create a type alias (ie template<typename T> using Vec = std::vector).
There's more.
4) Make names from a base class visible in the derived class despite overloading:
5) Change access of inherited elements, especially inherited from private bases:Code:struct Base {
virtual void f(int);
virtual void f(float);
};
struct Derived : public Base {
virtual void f(int); // Override (int) version.
using Base::f; // But let the compiler still find the (float) version.
};
Code:class Whatever : private std::vector<int> {
public:
typedef std::vector<int>::iterator iterator;
typedef std::vector<int>::const_iterator const_iterator;
using std::vector<int>::begin;
using std::vector<int>::end;
};
Re 2): Oh yes, my bad. I don't know what I was thinking...
And I forgot 1). I've seen it, of course.