c++11 - Move CComBSTR to std::vector? -
is there way move ccombstr object std::vector without copying underlying string? seems following code doesn't work.
ccombstr str(l"somestr"); std::vector<ccombstr> vstr; vstr.push_back((ccombstr)str.detach());
your code doesn't work because detach
gives bstr
, not ccombstr
. have used std::vector<bstr> vstr
, long realise bstr
points first character of string, there's length prefix before memory points (see, e.g. bstr (automation)), you'd need careful managing it.
alternatively, have used
ccombstr str(l"somestr"); std::vector<ccombstr> vstr; vstr.push_back(str);
which make copy of string.
the msdn page on ccombstr not indicate has move-semantics, might have been added code without documentation being updated. don't think though, in case std::move
solution in answer same second example: simple copy.
Comments
Post a Comment