我有C++代碼03看起來像這樣:將std :: tr1導入std - 它合法嗎?它是否改善便攜性?
#include <boost/tr1/unordered_map.hpp>
...
std::tr1::unordered_map<std::string, int> mystuff;
...
我開始懷疑,如果/當我將代碼轉換爲C++ 11,這(我猜)沒有按」我以後會吃虧沒有std::tr1::unordered_map
,而是有std::unordered_map
。所以,我想出了下面的技巧:
namespace std
{
using namespace ::std::tr1;
}
...
std::unordered_map<std::string, int> mystuff; // no tr1 now!
...
它是合法的(也許進口的東西到std
是被禁止的)?它會讓它更容易移植到C++ 11代碼中嗎?
我的編譯器(VS2010)仍然能夠理解'std :: tr1',即使現在所有東西都存在於'std'中。 – Benj