Различие между стиранием и удаляет

Если вы добавите немного margin-right к кнопке отмены (вместе с justify-content: flex-end на save_div). Это даст вам взгляд, который вы ищете.

.save_div {
  display: flex;
  justify-content: flex-end;
}

button.button_div:nth-child(2) {
  margin-right: 100px;
}
<div class="outermost_div additional">
  <div class="save_div">
    <button class="button_div" onClick={ props.on_selected}Save</button>
    <div class="divider" />
    <button class="button_div" onClick={props.on_cancel}>
                Cancel
            </button>
  </div>
</div>

47
задан aJ. 29 April 2009 в 03:44
поделиться

4 ответа

remove() doesn't actually delete elements from the container -- it only shunts non-deleted elements forwards on top of deleted elements. The key is to realise that remove() is designed to work on not just a container but on any arbitrary forward iterator pair: that means it can't actually delete the elements, because an arbitrary iterator pair doesn't necessarily have the ability to delete elements.

For example, pointers to the beginning and end of a regular C array are forward iterators and as such can be used with remove():

int foo[100];

...

remove(foo, foo + 100, 42);    // Remove all elements equal to 42

Here it's obvious that remove() cannot resize the array!

52
ответ дан 26 November 2019 в 19:33
поделиться

std :: remove не удаляет реальные объекты, скорее, толкает их к концу контейнера. Фактическое удаление и освобождение памяти осуществляется с помощью стирания. Итак:

(1). Есть ли какое-либо использование std :: remove, кроме использования его с функцией стирания.

Да, это помогает получить пару итераторов для новой последовательности, не беспокоясь о правильном перераспределении и т. Д.

(2) , Даже после выполнения std :: remove, почему a.size () возвращает 2, а не 1?

Контейнер все еще содержит эти объекты, у вас есть только новый набор итераторов для работы. Следовательно, размер все еще тот, что был раньше.

17
ответ дан 26 November 2019 в 19:33
поделиться

Самое простое, что я могу придумать:

erase () - это то, что вы можете сделать с элементом в контейнере. Используя итератор / индекс в контейнере, erase (it) удаляет из контейнера то, на что ссылается итератор.

remove () - это то, что вы можете сделать с диапазоном, -страивает этот диапазон, но не сотрите что-нибудь из диапазона.

6
ответ дан 26 November 2019 в 19:33
поделиться

remove doesn't "really" remove anything, because it can't.

In order to "actually" remove the elements from container you need to access container APIs. Where as remove works only with iterators irrespective of what containers those iterators points to. Hence, even if remove wants an "actual remove", it can't.

Remove overwrite "removed" elements by the following elements that were not removed and then it is up to the caller to decide to use the returned new logical end instead of the original end.

In your case remove logically removed 1 from vector a but size remained to 2 itself. Erase actually deleted the elements from vector. [ from vector new end to old end ]

The main idea of remove is it cannot change the number of elements and it just remove elements from a range as per criteria.

3
ответ дан 26 November 2019 в 19:33
поделиться
Другие вопросы по тегам:

Похожие вопросы: