Can I resize a vector that was moved from?

vector erase
resize 2d vector c++
vector resize implementation
vector::resize() vs reserve

I have some code in which I want to make absolutely sure that a moved-from std::vector will not leave secret data around (think about crypto key management). In my class' move constructor, I do something like:

X(X&& rhs): secret_vector{std::move(rhs.secret_vector)}{
    safe_zero(rhs.secret_vector); // zero out all elements

As you can see, I re-use the secret vector after moving from it. I looked at

Reusing a moved container?

but it was not absolutely clear that I can do this (I did not understand what "pre-conditions" really are).

My question is: can I resize a moved-from std::vector, perform some operation on it, then resize it back to zero?

My question is: can I resize a moved-from std::vector, perform some operation on it, then resize it back to zero?

A moved from object should be in unspecified but valid state.

So you have the right to resize it (no precondition required for that). safe_zero it, and clear it.

(I did not understand what "pre-conditions" really are).

There are state conditions that object should have to not invoke UB.

For example, operator[](std::size_t i) requires that i < size().

resize(), clear() doesn't have requirements.

vector::resize - C++ Reference, In overload (1), if T 's move constructor is not noexcept and T is not CopyInsertable into *this , vector will use the throwing move constructor. vector::resize() The function alters the container’s content in actual by inserting or deleting the elements from it. It happens so, If the given value of n is less

[defns.valid] valid but unspecified state value of an object that is not specified except that the object’s invariants are met and operations on the object behave as specified for its type

[Example: If an object x of type std::vector is in a valid but unspecified state, x.empty() can be called unconditionally, and x.front() can be called only if x.empty() returns false. — end example]

std::vector::resize does not have any preconditions. No matter what valid state a vector is in, resizing it would not have undefined behaviour (disregarding UB caused by constructors of contained elements; but those are not called when the argument is 0).

std::vector<T,Allocator>::resize, An STL container can only use the move constructor in it's resizing operation if std::vector<Y> copyVector = vectorToFill; std::cout << "Move� If a reallocation happens, the reallocation is itself up to linear in the entire vector size. Iterator validity In case the container shrinks, all iterators, pointers and references to elements that have not been removed remain valid after the resize and refer to the same elements they were referring to before the call.

Yes. The object is in valid but in unspecified state as stated in the linked question. That means that you cannot assume anything about the content of std::vector. Calling size is safe but it might not return the same value as before the move. The state of the vector is valid, meaning there are no dangling pointers inside or anything and all member functions including resize will work just fine. Moreover calling resize is one of the few meaningful functions to call because it "respecifies" the vector's state.

C++ noexcept and move constructors effect on performance in STL , This guide will use only PPI (Pixels Per Inch) to describe resolution. When an image is resized, its pixel information is changed. Vector graphics (such as clipart and charts in Word or Powerpoint) are not comprised of� You can save every page (all text, images, and vector objects on a page) to an image format using the File > Export To > Image > [Image Type] command. You can also export each image in a PDF to a separate image file. For more information, see Convert or export PDFs to other file formats.

What is Resizing? - All About Images, The benefit to vectors being used for print is that they can be resized without you could select just a portion of the image using these dots and move them� You are trying to resize different size images maintaining the original proportion. The width and height values you have introduced will be considered as maximum values only. You can check the resulting width and height values under each image preview.

Quick Lesson: Image Resize, Creating Graphic Designs for Print , Pressing the during any of the above operations will allow you to select multiple artboards. Artboard Tool Move Tool To reposition an artboard: Do one of the� These expenses are in addition to the cost to relocate/resize service and are the customer's responsibility. It is important that you meet with your contractor before, during and after completing the application to ensure your project is in-line with Vectren's requirements and local/state regulations.

Selecting, moving and resizing artboards, Once you have done this, you can resize any vector image as small as you need That way, when you combine shapes together or move stuff around, it doesn't� I'm trying to figure out how to resize a vector of vectors based upon the user's input. I'm making a method called setGrid which should take in the # of rows and columns and then generate a chessboard based upon that. I can resize outer vector no problem but how would I resize the inner vectors too?