vectorが空の時、 vector<...> v; ... @ if (!v.empty()) { for (auto it = v.begin(); it != v.end(); ++it) { .... } } と A for (auto it = v.begin(); it != v.end(); ++it) { .... } は同じですか?
質問です template < class T > struct F { template < class T2 > void Func( T2 ); template <> void Func( int i ); }; こういうクラスがあって、T2を取る関数を書く場合 template < class T > template < class T2 > void F<T>::Func( T2 ){...} でコンパイル通るのですが、2番目のintを取るように特殊化したものを template < class T > template <> void F<T>::Func( int i){...} とかくと C2244:関数の定義を既存の宣言と合致させることができませんでした となって通りません。どのように書けばいいのでしょうか? VS2003.netを使用してます
7.3.3 The using declaration [namespace.udecl] using-declaration: using typenameopt ::opt nested-name-specifier unqualified-id ; using :: unqualified-id ; 7.3.4 Using directive [namespace.udir] using-directive: using namespace ::opt nested-name-specifieropt namespace-name ;
#include <iostream> class Session {}; class SessionFactory {
public: Session Create( ); Session* CreatePtr( ); void Create(Session*& p); }; Session SessionFactory::Create( ) { Session s; return(s); } Session* SessionFactory::CreatePtr( ) { return(new Session( )); } void SessionFactory::Create(Session*& p) { p = new Session( ); } static SessionFactory f; // The one factory object int main( ) { Session* p1; Session* p2 = new Session( ); *p2 = f.Create( ); // Just assign the object returned from Create p1 = f.CreatePtr( ); // or return a pointer to a heap object f.Create(p1); // or update the pointer with the new address }
> I wrote a quick script to add redundant guards to all the source code > and did a full build again. The number of includes reported by the compiler > went down to 10,568 (from over 15,000). That means that there were about > 5,000 redundant includes in a full build. However, the overall build time > didn't change at all. > > Result: Zero. Apparently Visual Studio .NET 2003 (and probably most of > the major compilers) does a pretty good job caching those includes by itself.
これは数百ファイルからなるプロジェクトをVS .NET 2003でビルドするときの 話なんですが、のべ15,000回を超えるincludeが、”冗長”guard(=external include guard)をすることによって、10,568回に減ったそうです。