我可以将std :: basic_string用于非字符类型的东西吗?

Rog*_*mbe 1 c++ visual-c++

我的代码中有一个循环使用std::basic_string<HANDLE>,然后像这样等待它:

DWORD dwWaitResult = WaitForMultipleObjects((DWORD)handles.size(),
                                            handles.data(),
                                            FALSE, POLL_INTERVAL_MS);
Run Code Online (Sandbox Code Playgroud)

工作正常,但是当我打开/ W4和/ analyze时,Visual C++ 2008会发出以下警告(为简洁而减少并包装):

iosfwd(266) : warning C6001: Using uninitialized memory '*_First'
iosfwd(262) : while compiling class template member function
       'HANDLE *std::char_traits<_Elem>::assign(_Elem *,size_t,_Elem)'
        with [ _Elem=HANDLE ]
xstring(2155) : see reference to class template instantiation
       'std::char_traits<_Elem>' being compiled
        with [ _Elem=HANDLE ]
xstring(2148) : while compiling class template member function
       'void std::basic_string<_Elem>::_Tidy(bool,unsigned int)'
        with [ _Elem=HANDLE ]
.\MyCode.cpp(231) : see reference to class template instantiation
       'std::basic_string<_Elem>' being compiled
        with [ _Elem=HANDLE ]

iosfwd(222) : warning C6001: Using uninitialized memory '*_First1'
iosfwd(216) : while compiling class template member function
        'HANDLE *std::char_traits<_Elem>::_Copy_s
               (_Elem *,size_t,const _Elem *,size_t)'
        with [ _Elem=HANDLE ]
Run Code Online (Sandbox Code Playgroud)

问题:

  1. 将std :: basic_string用于不是简单字符类型(即charwchar_t)的东西是否合法?
  2. 如果是,我该怎么做才能摆脱这些警告?回答#pragma warning(disable)需要证明理由.
  3. 如果不是,为什么不呢?我该怎么用呢?

考虑到Boost已经出局,我们将获得额外的荣誉,我们仅限于Visual C++ 2008中的STL实现; 允许TR1的Visual C++位.

Goz*_*Goz 6

使用std :: vector而不是试图将那个方形塞子塞进圆孔中有什么问题?