Search code examples
c++11atl

Move CComBSTR to std::vector?


Is there a way to move CComBSTR object to std::vector without copying the underlying string? It seems the following code doesn't work.

CComBSTR str(L"SomeStr");
std::vector<CComBSTR> vStr;

vStr.push_back((CComBSTR)str.Detach());

Solution

  • I've done some experiment and seems the latest CComBSTR supports move semantics so it can be written as:

    CComBSTR str(L"SomeStr");
    std::vector<CComBSTR> vStr;
    
    vStr.push_back(std::move(str));