QVarLengthArray Class
template <typename T, qsizetype Prealloc = QVarLengthArrayDefaultPrealloc> class QVarLengthArrayQVarLengthArray 클래스는 저수준 가변 길이 배열을 제공합니다. 더 보기...
Header: | #include <QVarLengthArray> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
상속합니다: | QVLABase 및 QVLAStorage |
참고: 이 클래스의 모든 함수는 재진입됩니다.
공용 유형
const_iterator | |
const_pointer | |
const_reference | |
const_reverse_iterator | |
difference_type | |
iterator | |
pointer | |
reference | |
reverse_iterator | |
size_type | |
value_type |
공용 함수
QVarLengthArray() | |
QVarLengthArray(qsizetype size) | |
QVarLengthArray(std::initializer_list<T> args) | |
QVarLengthArray(InputIterator first, InputIterator last) | |
(since 6.4) | QVarLengthArray(qsizetype size, const T &v) |
QVarLengthArray(const QVarLengthArray<T, Prealloc> &other) | |
(since 6.0) | QVarLengthArray(QVarLengthArray<T, Prealloc> &&other) |
~QVarLengthArray() | |
void | append(const T &t) |
void | append(const T *buf, qsizetype size) |
void | append(T &&t) |
(since 6.6) QVarLengthArray<T, Prealloc> & | assign(std::initializer_list<T> list) |
(since 6.6) QVarLengthArray<T, Prealloc> & | assign(InputIterator first, InputIterator last) |
(since 6.6) QVarLengthArray<T, Prealloc> & | assign(qsizetype n, const T &t) |
const T & | at(qsizetype i) const |
T & | back() |
const T & | back() const |
QVarLengthArray<T, Prealloc>::iterator | begin() |
QVarLengthArray<T, Prealloc>::const_iterator | begin() const |
qsizetype | capacity() const |
QVarLengthArray<T, Prealloc>::const_iterator | cbegin() const |
QVarLengthArray<T, Prealloc>::const_iterator | cend() const |
void | clear() |
QVarLengthArray<T, Prealloc>::const_iterator | constBegin() const |
const T * | constData() const |
QVarLengthArray<T, Prealloc>::const_iterator | constEnd() const |
bool | contains(const AT &value) const |
qsizetype | count() const |
QVarLengthArray<T, Prealloc>::const_reverse_iterator | crbegin() const |
QVarLengthArray<T, Prealloc>::const_reverse_iterator | crend() const |
T * | data() |
const T * | data() const |
(since 6.3) QVarLengthArray<T, Prealloc>::iterator | emplace(QVarLengthArray<T, Prealloc>::const_iterator pos, Args &&... args) |
(since 6.3) T & | emplace_back(Args &&... args) |
bool | empty() const |
QVarLengthArray<T, Prealloc>::iterator | end() |
QVarLengthArray<T, Prealloc>::const_iterator | end() const |
QVarLengthArray<T, Prealloc>::iterator | erase(QVarLengthArray<T, Prealloc>::const_iterator pos) |
QVarLengthArray<T, Prealloc>::iterator | erase(QVarLengthArray<T, Prealloc>::const_iterator begin, QVarLengthArray<T, Prealloc>::const_iterator end) |
T & | first() |
const T & | first() const |
T & | front() |
const T & | front() const |
qsizetype | indexOf(const AT &value, qsizetype from = 0) const |
void | insert(qsizetype i, T &&value) |
void | insert(qsizetype i, const T &value) |
QVarLengthArray<T, Prealloc>::iterator | insert(QVarLengthArray<T, Prealloc>::const_iterator before, qsizetype count, const T &value) |
QVarLengthArray<T, Prealloc>::iterator | insert(QVarLengthArray<T, Prealloc>::const_iterator before, T &&value) |
QVarLengthArray<T, Prealloc>::iterator | insert(QVarLengthArray<T, Prealloc>::const_iterator before, const T &value) |
void | insert(qsizetype i, qsizetype count, const T &value) |
bool | isEmpty() const |
T & | last() |
const T & | last() const |
qsizetype | lastIndexOf(const AT &value, qsizetype from = -1) const |
qsizetype | length() const |
(since 6.8) qsizetype | max_size() const |
void | pop_back() |
void | push_back(const T &t) |
void | push_back(T &&t) |
QVarLengthArray<T, Prealloc>::reverse_iterator | rbegin() |
QVarLengthArray<T, Prealloc>::const_reverse_iterator | rbegin() const |
void | remove(qsizetype i, qsizetype count = 1) |
(since 6.1) qsizetype | removeAll(const AT &t) |
(since 6.1) qsizetype | removeIf(Predicate pred) |
void | removeLast() |
(since 6.1) bool | removeOne(const AT &t) |
QVarLengthArray<T, Prealloc>::reverse_iterator | rend() |
QVarLengthArray<T, Prealloc>::const_reverse_iterator | rend() const |
void | replace(qsizetype i, const T &value) |
void | reserve(qsizetype size) |
void | resize(qsizetype size) |
(since 6.4) void | resize(qsizetype size, const T &v) |
void | shrink_to_fit() |
qsizetype | size() const |
void | squeeze() |
T | value(qsizetype i) const |
T | value(qsizetype i, const T &defaultValue) const |
QVarLengthArray<T, Prealloc> & | operator+=(const T &value) |
QVarLengthArray<T, Prealloc> & | operator+=(T &&value) |
QVarLengthArray<T, Prealloc> & | operator<<(const T &value) |
QVarLengthArray<T, Prealloc> & | operator<<(T &&value) |
(since 6.0) QVarLengthArray<T, Prealloc> & | operator=(QVarLengthArray<T, Prealloc> &&other) |
QVarLengthArray<T, Prealloc> & | operator=(const QVarLengthArray<T, Prealloc> &other) |
QVarLengthArray<T, Prealloc> & | operator=(std::initializer_list<T> list) |
T & | operator[](qsizetype i) |
const T & | operator[](qsizetype i) const |
정적 공용 멤버
(since 6.8) qsizetype | maxSize() |
관련 비회원
(since 6.1) qsizetype | erase(QVarLengthArray<T, Prealloc> &array, const AT &t) |
(since 6.1) qsizetype | erase_if(QVarLengthArray<T, Prealloc> &array, Predicate pred) |
size_t | qHash(const QVarLengthArray<T, Prealloc> &key, size_t seed = 0) |
bool | operator!=(const QVarLengthArray<T, Prealloc1> &left, const QVarLengthArray<T, Prealloc2> &right) |
bool | operator<(const QVarLengthArray<T, Prealloc1> &lhs, const QVarLengthArray<T, Prealloc2> &rhs) |
bool | operator<=(const QVarLengthArray<T, Prealloc1> &lhs, const QVarLengthArray<T, Prealloc2> &rhs) |
bool | operator==(const QVarLengthArray<T, Prealloc1> &left, const QVarLengthArray<T, Prealloc2> &right) |
bool | operator>(const QVarLengthArray<T, Prealloc1> &lhs, const QVarLengthArray<T, Prealloc2> &rhs) |
bool | operator>=(const QVarLengthArray<T, Prealloc1> &lhs, const QVarLengthArray<T, Prealloc2> &rhs) |
상세 설명
C++ 언어는 스택에서 가변 길이 배열을 지원하지 않습니다. 예를 들어 다음 코드는 컴파일되지 않습니다:
int myfunc(int n) { int table[n + 1]; // WRONG ... return table[n]; }
대안은 힙에 배열을 할당하는 것입니다( new
):
int myfunc(int n) { int *table = new int[n + 1]; ... int ret = table[n]; delete[] table; return ret; }
그러나 애플리케이션의 내부 루프에서 myfunc()가 매우 자주 호출되는 경우 힙 할당은 속도 저하의 주요 원인이 될 수 있습니다.
QVarLengthArray는 C++ 언어에서 이 문제를 해결하기 위한 시도입니다. 스택에 일정 수의 요소를 할당하고 배열의 크기를 더 크게 조정하면 자동으로 힙을 대신 사용합니다. 스택 할당은 힙 할당보다 훨씬 빠르다는 장점이 있습니다.
예시:
int myfunc(int n) { QVarLengthArray<int, 1024> array(n + 1); ... return array[n]; }
위의 예에서 QVarLengthArray는 스택에 1024개의 요소를 미리 할당하고 n + 1
가 1024보다 크지 않으면 이를 사용합니다. 두 번째 템플릿 인수를 생략하면 QVarLengthArray의 기본값인 256이 사용됩니다.
QVarLengthArray의 값 유형은 할당 가능한 데이터 유형이어야 합니다. 이는 일반적으로 사용되는 대부분의 데이터 유형을 포함하지만, 예를 들어 컴파일러는 QWidget 를 값으로 저장하는 대신 QWidget *를 저장하도록 허용하지 않습니다.
QVarLengthArray는 QList 와 마찬가지로 크기 조정이 가능한 배열 데이터 구조를 제공합니다. 두 클래스의 주요 차이점은 다음과 같습니다:
- QVarLengthArray의 API는 훨씬 더 낮은 수준이며 QList 의 기능 중 일부가 부족합니다.
- 값이 기본 유형인 경우 QVarLengthArray는 메모리를 초기화하지 않습니다. (QList 은 항상 초기화합니다.)
- QList 는 메모리 최적화로 암시적 공유를 사용합니다. QVarLengthArray는 해당 기능을 제공하지 않지만, 일반적으로 특히 타이트한 루프에서 오버헤드가 감소하여 약간 더 나은 성능을 제공합니다.
요약하면, QVarLengthArray는 매우 특정한 경우에만 의미가 있는 저수준 최적화 클래스입니다. Qt 내부의 몇 군데에서 사용되며 고급 사용자의 편의를 위해 Qt의 공용 API에 추가되었습니다.
QList 를참조하십시오 .
멤버 유형 문서
[alias]
QVarLengthArray::const_iterator
상수 T *에 대한 Typedef. STL 호환성을 위해 제공됩니다.
[alias]
QVarLengthArray::const_pointer
상수 T *에 대한 Typedef. STL 호환성을 위해 제공됩니다.
[alias]
QVarLengthArray::const_reference
const T &용 Typedef. STL 호환성을 위해 제공됩니다.
[alias]
QVarLengthArray::const_reverse_iterator
std::reverse_iterator<const T*>
. STL 호환성을 위해 제공됩니다.
[alias]
QVarLengthArray::difference_type
ptrdiff_t의 경우 Typedef. STL 호환성을 위해 제공됩니다.
[alias]
QVarLengthArray::iterator
T *의 경우 Typedef. STL 호환성을 위해 제공됩니다.
[alias]
QVarLengthArray::pointer
T *의 경우 Typedef. STL 호환성을 위해 제공됩니다.
[alias]
QVarLengthArray::reference
T &용 Typedef. STL 호환성을 위해 제공됩니다.
[alias]
QVarLengthArray::reverse_iterator
std::reverse_iterator<T*>
. STL 호환성을 위해 제공됩니다.
[alias]
QVarLengthArray::size_type
int. STL 호환성을 위해 제공됩니다.
[alias]
QVarLengthArray::value_type
STL 호환성을 위해 제공되는 T용 Typedef입니다.
멤버 함수 문서
[static constexpr noexcept, since 6.8]
qsizetype QVarLengthArray::maxSize()
[constexpr noexcept, since 6.8]
qsizetype QVarLengthArray::max_size() const
배열이 이론적으로 보유할 수 있는 최대 요소 수를 반환합니다. 실제로는 시스템에서 사용할 수 있는 메모리의 양에 따라 이보다 훨씬 작을 수 있습니다.
이 함수는 Qt 6.8에 도입되었습니다.
void QVarLengthArray::insert(qsizetype i, T &&value)
void QVarLengthArray::insert(qsizetype i, const T &value)
배열의 인덱스 위치 i 에 value 를 삽입합니다. i 가 0이면 벡터 앞에 값이 추가됩니다. i 가 size()인 경우 벡터에 값이 추가됩니다.
큰 배열의 경우 이 작업은 인덱스 i 이상의 모든 항목을 메모리에서 한 위치씩 더 이동해야 하므로 속도가 느려질 수 있습니다(선형 시간). 빠른 insert() 함수를 제공하는 컨테이너 클래스를 원한다면 대신 std::list를 사용하세요.
remove()도 참조하세요 .
QVarLengthArray<T, Prealloc>::iterator QVarLengthArray::insert(QVarLengthArray<T, Prealloc>::const_iterator before, T &&value)
QVarLengthArray<T, Prealloc>::iterator QVarLengthArray::insert(QVarLengthArray<T, Prealloc>::const_iterator before, const T &value)
이것은 오버로드된 함수입니다.
이터레이터 before 가 가리키는 항목 앞에 value 를 삽입합니다. 삽입된 항목을 가리키는 이터레이터를 반환합니다.
[noexcept]
QVarLengthArray::QVarLengthArray()
초기 크기가 0인 배열을 생성합니다.
[explicit]
QVarLengthArray::QVarLengthArray(qsizetype size)
초기 크기가 size 요소인 배열을 구축합니다.
값 유형이 원시 유형(예: 문자, 정수, 실수)이거나 포인터 유형(예: QWidget *)인 경우 요소는 초기화되지 않습니다. 다른 유형의 경우 요소는 기본적으로 구성된 값으로 초기화됩니다.
QVarLengthArray::QVarLengthArray(std::initializer_list<T> args)
args 에서 제공한 std::initializer_list 로부터 배열을 구축합니다.
template <typename InputIterator, QVarLengthArray<T, Prealloc>::if_input_iterator<InputIterator> = true> QVarLengthArray::QVarLengthArray(InputIterator first, InputIterator last)
이터레이터 범위의 콘텐츠로 배열을 생성합니다 [first, last).
이 생성자는 InputIterator
이 LegacyInputIterator의 요구 사항을 충족하는 경우에만 과부하 해결에 참여합니다.
InputIterator
의 값 유형은 T
로 변환 가능해야 합니다.
[explicit, since 6.4]
QVarLengthArray::QVarLengthArray(qsizetype size, const T &v)
v 의 복사본으로 채워진 초기 크기가 size 요소로 구성된 배열을 생성합니다.
참고: 이 생성자는 T
가 복사 가능한 경우에만 사용할 수 있습니다.
이 함수는 Qt 6.4에 도입되었습니다.
QVarLengthArray::QVarLengthArray(const QVarLengthArray<T, Prealloc> &other)
other 의 복사본을 생성합니다.
[noexcept(...), since 6.0]
QVarLengthArray::QVarLengthArray(QVarLengthArray<T, Prealloc> &&other)
이동 - other 에서 이 가변 길이 배열을 구성합니다. 이동 후 other 은 비어 있습니다.
이 함수는 Qt 6.0에 도입되었습니다.
참고: 이 함수는 std::is_nothrow_move_constructible_v<T>
가 true
일 때를 제외하고는 사용되지 않습니다.
QVarLengthArray::~QVarLengthArray()
배열을 파괴합니다.
void QVarLengthArray::append(const T &t)
필요한 경우 배열을 확장하여 t 항목을 배열에 추가합니다.
removeLast()도 참조하세요 .
void QVarLengthArray::append(const T *buf, qsizetype size)
buf 에서 참조하는 항목의 size 개수를 이 배열에 추가합니다.
void QVarLengthArray::append(T &&t)
이 함수는 append를 오버로드합니다.
참고: append()의 lvalue 오버로드와 달리 이미 *this
의 요소인 객체에 대한 참조를 전달하면 정의되지 않은 동작이 발생합니다:
vla.append(std::move(vla[0])); // BUG: passing an object that is already in the container
[since 6.6]
QVarLengthArray<T, Prealloc> &QVarLengthArray::assign(std::initializer_list<T> list)
이 컨테이너의 내용을 list 의 요소 복사본으로 바꿉니다.
이 컨테이너의 크기는 list 의 요소 수와 같습니다.
이 함수는 list 의 엘리먼트 수가 컨테이너의 용량을 초과하는 경우에만 메모리를 할당합니다.
이 함수는 Qt 6.6에 도입되었습니다.
[since 6.6]
template <typename InputIterator, QVarLengthArray<T, Prealloc>::if_input_iterator<InputIterator> = true> QVarLengthArray<T, Prealloc> &QVarLengthArray::assign(InputIterator first, InputIterator last)
이 컨테이너의 내용을 이터레이터 범위 [first, last]의 요소 복사본으로 바꿉니다.
이 컨테이너의 크기는 범위 [first, last]의 요소 수와 같습니다. 이 함수는 범위의 요소 수가 컨테이너의 용량을 초과하는 경우에만 메모리를 할당합니다.
이 함수 과부하는 InputIterator
이 LegacyInputIterator의 요구 사항을 충족하는 경우에만 과부하 해결에 참여합니다.
인자 중 하나가 *이것에 대한 이터레이터인 경우 동작이 정의되지 않습니다.
이 함수는 Qt 6.6에 도입되었습니다.
[since 6.6]
QVarLengthArray<T, Prealloc> &QVarLengthArray::assign(qsizetype n, const T &t)
이 컨테이너의 내용을 t 의 n 사본으로 바꿉니다.
이 컨테이너의 크기는 n 과 같습니다. 이 함수는 n 이 컨테이너의 용량을 초과하는 경우에만 메모리를 할당합니다.
이 함수는 Qt 6.6에 도입되었습니다.
const T &QVarLengthArray::at(qsizetype i) const
인덱스 위치 i 에 있는 항목에 대한 참조를 반환합니다.
i 는 배열에서 유효한 인덱스 위치여야 합니다(즉, 0 <= i < size()).
value() 및 operator[]()도 참조하세요 .
T &QVarLengthArray::back()
last()와 동일합니다. STL 호환성을 위해 제공됩니다.
const T &QVarLengthArray::back() const
과부하가 걸린 기능입니다.
QVarLengthArray<T, Prealloc>::iterator QVarLengthArray::begin()
배열의 첫 번째 항목을 가리키는 STL 스타일 이터레이터를 반환합니다.
constBegin() 및 end()도 참조하세요 .
QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray::begin() const
과부하가 걸린 기능입니다.
qsizetype QVarLengthArray::capacity() const
강제 재할당 없이 배열에 저장할 수 있는 최대 엘리먼트 수를 반환합니다.
이 함수의 유일한 목적은 QVarLengthArray 의 메모리 사용량을 미세 조정하는 수단을 제공하는 것입니다. 일반적으로 이 함수를 호출할 필요는 거의 없습니다. 배열에 있는 항목 수를 알고 싶으면 size()를 호출하세요.
reserve() 및 squeeze()도 참조하세요 .
QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray::cbegin() const
배열의 첫 번째 항목을 가리키는 상수 STL 스타일 이터레이터를 반환합니다.
QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray::cend() const
배열의 마지막 항목 뒤에 있는 가상의 항목을 가리키는 상수 STL 스타일 이터레이터를 반환합니다.
void QVarLengthArray::clear()
배열에서 모든 요소를 제거합니다.
resize(0)과 동일합니다.
QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray::constBegin() const
배열의 첫 번째 항목을 가리키는 상수 STL 스타일 이터레이터를 반환합니다.
const T *QVarLengthArray::constData() const
배열에 저장된 데이터에 대한 상수 포인터를 반환합니다. 이 포인터는 배열의 항목에 액세스하는 데 사용할 수 있습니다. 배열이 재할당되지 않는 한 포인터는 유효하게 유지됩니다.
이 함수는 일반 C++ 배열을 받아들이는 함수에 배열을 전달할 때 주로 유용합니다.
data() 및 operator[]()도 참조하세요 .
QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray::constEnd() const
배열의 마지막 항목 뒤에 있는 가상의 항목을 가리키는 상수 STL 스타일 이터레이터를 반환합니다.
constBegin() 및 end()도 참조하세요 .
template <typename AT = T> bool QVarLengthArray::contains(const AT &value) const
배열에 value 이 포함되어 있으면 true
을 반환하고, 그렇지 않으면 false
을 반환합니다.
이 함수를 사용하려면 값 유형에 operator==()
의 구현이 있어야 합니다.
indexOf() 및 lastIndexOf()도 참조하세요 .
qsizetype QVarLengthArray::count() const
size()와 동일합니다.
QVarLengthArray<T, Prealloc>::const_reverse_iterator QVarLengthArray::crbegin() const
가변 길이 배열의 첫 번째 항목을 역순으로 가리키는 상수 STL 스타일 리버스 이터레이터를 반환합니다.
begin(), rbegin() 및 rend()도 참조하세요 .
QVarLengthArray<T, Prealloc>::const_reverse_iterator QVarLengthArray::crend() const
가변 길이 배열의 마지막 항목을 역순으로 지나쳐서 하나를 가리키는 상수 STL 스타일 역이터레이터를 반환합니다.
end(), rend() 및 rbegin()도 참조하세요 .
T *QVarLengthArray::data()
배열에 저장된 데이터에 대한 포인터를 반환합니다. 포인터는 배열의 항목에 액세스하고 수정하는 데 사용할 수 있습니다.
예시:
QVarLengthArray<int> array(10); int *data = array.data(); for (int i = 0; i < 10; ++i) data[i] = 2 * i;
배열이 재할당되지 않는 한 포인터는 유효합니다.
이 함수는 주로 일반 C++ 배열을 받아들이는 함수에 배열을 전달할 때 유용합니다.
constData() 및 operator[]()도 참조하세요 .
const T *QVarLengthArray::data() const
과부하가 걸린 기능입니다.
[since 6.3]
template <typename... Args> QVarLengthArray<T, Prealloc>::iterator QVarLengthArray::emplace(QVarLengthArray<T, Prealloc>::const_iterator pos, Args &&... args)
이터레이터 pos 가 가리키는 항목 앞에 항목을 삽입하고 args 을 생성자에게 전달합니다.
삽입된 항목을 가리키는 이터레이터를 반환합니다.
이 함수는 Qt 6.3에 도입되었습니다.
[since 6.3]
template <typename... Args> T &QVarLengthArray::emplace_back(Args &&... args)
이 QVarLengthArray 뒤에 항목을 삽입하고 args 을 생성자에게 전달합니다.
삽입된 항목에 대한 참조를 반환합니다.
이 함수는 Qt 6.3에 도입되었습니다.
bool QVarLengthArray::empty() const
배열의 크기가 0이면 true
을 반환하고, 그렇지 않으면 false
을 반환합니다.
isEmpty()와 동일합니다. STL 호환성을 위해 제공됩니다.
QVarLengthArray<T, Prealloc>::iterator QVarLengthArray::end()
배열의 마지막 항목 뒤에 있는 가상의 항목을 가리키는 STL 스타일 이터레이터를 반환합니다.
QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray::end() const
과부하가 걸린 기능입니다.
QVarLengthArray<T, Prealloc>::iterator QVarLengthArray::erase(QVarLengthArray<T, Prealloc>::const_iterator pos)
반복자 pos 가 가리키는 항목을 벡터에서 제거하고 반복자를 벡터의 다음 항목( end()일 수 있음)으로 반환합니다.
QVarLengthArray<T, Prealloc>::iterator QVarLengthArray::erase(QVarLengthArray<T, Prealloc>::const_iterator begin, QVarLengthArray<T, Prealloc>::const_iterator end)
과부하가 걸린 함수입니다.
begin 에서 end 까지의 모든 항목을 제거합니다. 호출 전에 end 이 참조한 것과 동일한 항목에 대한 이터레이터를 반환합니다.
T &QVarLengthArray::first()
배열의 첫 번째 항목에 대한 참조를 반환합니다. 배열은 비어 있지 않아야 합니다. 배열이 비어 있을 수 있는 경우 이 함수를 호출하기 전에 isEmpty()를 확인하세요.
const T &QVarLengthArray::first() const
과부하가 걸린 기능입니다.
T &QVarLengthArray::front()
first()와 동일합니다. STL 호환성을 위해 제공됩니다.
const T &QVarLengthArray::front() const
과부하가 걸린 기능입니다.
template <typename AT = T> qsizetype QVarLengthArray::indexOf(const AT &value, qsizetype from = 0) const
인덱스 위치 from 에서 앞으로 검색하여 배열에서 value 이 처음 나오는 인덱스 위치를 반환합니다. 일치하는 항목이 없으면 -1을 반환합니다.
이 함수를 사용하려면 값 유형이 operator==()
로 구현되어야 합니다.
lastIndexOf() 및 contains()도 참조하세요 .
QVarLengthArray<T, Prealloc>::iterator QVarLengthArray::insert(QVarLengthArray<T, Prealloc>::const_iterator before, qsizetype count, const T &value)
이터레이터 before 가 가리키는 항목 앞에 value 의 count 복사본을 삽입합니다. 삽입된 항목 중 첫 번째 항목을 가리키는 이터레이터를 반환합니다.
void QVarLengthArray::insert(qsizetype i, qsizetype count, const T &value)
이것은 과부하된 함수입니다.
벡터의 인덱스 위치 i 에 value 의 count 복사본을 삽입합니다.
bool QVarLengthArray::isEmpty() const
배열의 크기가 0이면 true
을 반환하고, 그렇지 않으면 false
을 반환합니다.
T &QVarLengthArray::last()
배열의 마지막 항목에 대한 참조를 반환합니다. 배열은 비어 있지 않아야 합니다. 배열이 비어 있을 수 있는 경우 이 함수를 호출하기 전에 isEmpty()를 확인하세요.
const T &QVarLengthArray::last() const
과부하가 걸린 기능입니다.
template <typename AT = T> qsizetype QVarLengthArray::lastIndexOf(const AT &value, qsizetype from = -1) const
인덱스 위치 from 에서 역순으로 검색하여 배열에서 value 값이 마지막으로 발생한 인덱스 위치를 반환합니다. from 이 -1(기본값)이면 마지막 항목부터 검색이 시작됩니다. 일치하는 항목이 없으면 -1을 반환합니다.
이 함수를 사용하려면 값 유형이 operator==()
로 구현되어야 합니다.
indexOf() 및 contains()도 참조하세요 .
qsizetype QVarLengthArray::length() const
size()와 동일합니다.
void QVarLengthArray::pop_back()
removeLast()와 동일합니다. STL 호환성을 위해 제공됩니다.
void QVarLengthArray::push_back(const T &t)
필요한 경우 배열을 확장하여 t 항목을 배열에 추가합니다. STL 호환성을 위해 제공됩니다.
void QVarLengthArray::push_back(T &&t)
이 함수는 push_back을 오버로드합니다.
참고: push_back()의 lvalue 오버로드와 달리 이미 *this
의 요소인 객체에 대한 참조를 전달하면 정의되지 않은 동작이 발생합니다:
vla.push_back(std::move(vla[0])); // BUG: passing an object that is already in the container
QVarLengthArray<T, Prealloc>::reverse_iterator QVarLengthArray::rbegin()
가변 길이 배열의 첫 번째 항목을 역순으로 가리키는 STL 스타일 역이터레이터를 반환합니다.
begin(), crbegin() 및 rend()도 참조하세요 .
QVarLengthArray<T, Prealloc>::const_reverse_iterator QVarLengthArray::rbegin() const
과부하가 걸린 기능입니다.
void QVarLengthArray::remove(qsizetype i, qsizetype count = 1)
이 함수는 오버로드된 함수입니다.
인덱스 위치 i 부터 시작하여 배열의 중간에서 count 요소를 제거합니다.
[since 6.1]
template <typename AT = T> qsizetype QVarLengthArray::removeAll(const AT &t)
배열에서 t 와 비교되는 모든 요소를 제거합니다. 제거된 요소가 있으면 그 수를 반환합니다.
이 함수는 Qt 6.1에 도입되었습니다.
removeOne()도 참조하십시오 .
[since 6.1]
template <typename Predicate> qsizetype QVarLengthArray::removeIf(Predicate pred)
pred 술어가 참을 반환하는 모든 요소를 배열에서 제거합니다. 제거된 엘리먼트가 있으면 그 수를 반환합니다.
이 함수는 Qt 6.1에 도입되었습니다.
removeAll()도 참조하세요 .
void QVarLengthArray::removeLast()
배열의 크기를 1씩 줄입니다. 할당된 크기는 변경되지 않습니다.
append()도 참조하세요 .
[since 6.1]
template <typename AT = T> bool QVarLengthArray::removeOne(const AT &t)
배열에서 t 과 비교되는 첫 번째 요소를 제거합니다. 요소가 실제로 제거되었는지 여부를 반환합니다.
이 함수는 Qt 6.1에 도입되었습니다.
removeAll()도 참조하세요 .
QVarLengthArray<T, Prealloc>::reverse_iterator QVarLengthArray::rend()
가변 길이 배열의 마지막 항목을 역순으로 지나가는 항목을 가리키는 STL 스타일 역이터레이터를 반환합니다.
end(), crend() 및 rbegin()도 참조하세요 .
QVarLengthArray<T, Prealloc>::const_reverse_iterator QVarLengthArray::rend() const
과부하가 걸린 기능입니다.
void QVarLengthArray::replace(qsizetype i, const T &value)
인덱스 위치 i 의 항목을 value 로 바꿉니다.
i 는 배열에서 유효한 인덱스 위치여야 합니다(즉, 0 <= i < size()).
operator[]() 및 remove()도 참조하세요 .
void QVarLengthArray::reserve(qsizetype size)
최소 size 요소에 대한 메모리 할당을 시도합니다. 배열이 얼마나 커질 수 있는지 미리 알고 있다면 이 함수를 호출할 수 있으며 resize()를 자주 호출하면 더 나은 성능을 얻을 수 있습니다. size 이 과소평가된 경우 최악의 경우 QVarLengthArray 이 약간 느려질 수 있습니다.
이 함수의 유일한 목적은 QVarLengthArray 의 메모리 사용량을 미세 조정할 수 있는 수단을 제공하는 것입니다. 일반적으로 이 함수를 호출할 필요는 거의 없습니다. 배열의 크기를 변경하려면 resize()를 호출하세요.
capacity() 및 squeeze()도 참조하세요 .
void QVarLengthArray::resize(qsizetype size)
배열의 크기를 size 으로 설정합니다. size 이 현재 크기보다 크면 요소가 끝에 추가됩니다. size 이 현재 크기보다 작으면 끝에서 요소가 제거됩니다.
값 유형이 기본 유형(예: 문자, 정수, 실수)이거나 포인터 유형(예: QWidget *)인 경우 새 요소는 초기화되지 않습니다. 다른 유형의 경우 요소는 기본적으로 구성된 값으로 초기화됩니다.
[since 6.4]
void QVarLengthArray::resize(qsizetype size, const T &v)
배열의 크기를 size 로 설정합니다. size 이 현재 크기보다 크면 v 의 복사본이 끝에 추가됩니다. size 이 현재 크기보다 작으면 끝에서 요소가 제거됩니다.
참고: 이 함수는 T
복사 구성이 가능한 경우에만 사용할 수 있습니다.
이 함수는 Qt 6.4에 도입되었습니다.
void QVarLengthArray::shrink_to_fit()
squeeze()와 동일합니다. STL 호환성을 위해 제공됩니다.
qsizetype QVarLengthArray::size() const
배열의 요소 수를 반환합니다.
void QVarLengthArray::squeeze()
항목을 저장하는 데 필요하지 않은 메모리를 해제합니다. 컨테이너가 스택 할당에 저장 공간을 맞출 수 있으면 힙 할당을 해제하고 요소를 다시 스택으로 복사합니다.
이 함수의 유일한 목적은 QVarLengthArray 의 메모리 사용량을 미세 조정할 수 있는 수단을 제공하는 것입니다. 일반적으로 이 함수를 호출할 필요는 거의 없습니다.
reserve(), capacity(), resize()도 참조하세요 .
T QVarLengthArray::value(qsizetype i) const
인덱스 위치 i 의 값을 반환합니다.
i 인덱스가 범위를 벗어난 경우 이 함수는 기본적으로 구성된 값을 반환합니다. i 가 범위 내에 있다고 확신하는 경우 at() 대신 약간 더 빠른 값을 사용할 수 있습니다.
at() 및 operator[]()도 참조하세요 .
T QVarLengthArray::value(qsizetype i, const T &defaultValue) const
이 함수는 오버로드된 함수입니다.
i 인덱스가 범위를 벗어난 경우 이 함수는 defaultValue 을 반환합니다.
QVarLengthArray<T, Prealloc> &QVarLengthArray::operator+=(const T &value)
value 을 배열에 추가하고 이 벡터에 대한 참조를 반환합니다.
append() 및 operator<<()도 참조하세요 .
QVarLengthArray<T, Prealloc> &QVarLengthArray::operator+=(T &&value)
이 함수는 과부하된 함수입니다.
append() 및 operator<<()도 참조하세요 .
QVarLengthArray<T, Prealloc> &QVarLengthArray::operator<<(const T &value)
value 을 배열에 추가하고 이 벡터에 대한 참조를 반환합니다.
append() 및 operator+=()도 참조하세요 .
QVarLengthArray<T, Prealloc> &QVarLengthArray::operator<<(T &&value)
이 함수는 과부하된 함수입니다.
append() 및 operator+=()도 참조하세요 .
[noexcept(...), since 6.0]
QVarLengthArray<T, Prealloc> &QVarLengthArray::operator=(QVarLengthArray<T, Prealloc> &&other)
이동 - other 을 이 배열에 할당하고 이 배열에 대한 참조를 반환합니다. 이동 후 other 은 비어 있습니다.
이 함수는 Qt 6.0에 도입되었습니다.
참고: 이 함수는 std::is_nothrow_move_constructible_v<T>
가 true
일 때를 제외하고는 사용되지 않습니다.
QVarLengthArray<T, Prealloc> &QVarLengthArray::operator=(const QVarLengthArray<T, Prealloc> &other)
이 배열에 other 을 할당하고 이 배열에 대한 참조를 반환합니다.
QVarLengthArray<T, Prealloc> &QVarLengthArray::operator=(std::initializer_list<T> list)
list 값을 이 배열에 할당하고 이 배열에 대한 참조를 반환합니다.
T &QVarLengthArray::operator[](qsizetype i)
인덱스 위치 i 에 있는 항목에 대한 참조를 반환합니다.
i 는 배열에서 유효한 인덱스 위치여야 합니다(즉, 0 <= i < size()).
const T &QVarLengthArray::operator[](qsizetype i) const
과부하가 걸린 기능입니다.
관련 비회원
[since 6.1]
template <typename T, qsizetype Prealloc, typename AT> qsizetype erase(QVarLengthArray<T, Prealloc> &array, const AT &t)
array 배열에서 t 과 비교되는 모든 요소를 제거합니다. 제거된 요소가 있는 경우 제거된 요소의 수를 반환합니다.
참고: t 은 array 내부의 요소에 대한 참조가 될 수 없습니다. 그렇지 않은지 확실하지 않은 경우 t 의 복사본을 가져와서 복사본으로 이 함수를 호출하세요.
이 함수는 Qt 6.1에 도입되었습니다.
erase_if()도 참조하십시오 .
[since 6.1]
template <typename T, qsizetype Prealloc, typename Predicate> qsizetype erase_if(QVarLengthArray<T, Prealloc> &array, Predicate pred)
pred 술어가 참을 반환하는 모든 요소를 목록에서 제거합니다 array. 제거된 엘리먼트가 있으면 그 수를 반환합니다.
이 함수는 Qt 6.1에 도입되었습니다.
erase()도 참조하십시오 .
[noexcept(...)]
template <typename T, qsizetype Prealloc> size_t qHash(const QVarLengthArray<T, Prealloc> &key, size_t seed = 0)
seed 을 사용하여 key 에 대한 해시값을 반환합니다.
T
유형은 qHash()에서 지원되어야 합니다.
참고: 이 함수는 QtPrivate::QNothrowHashable_v<T>
가 true
인 경우를 제외하고는 사용할 수 없습니다.
template <typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator!=(const QVarLengthArray<T, Prealloc1> &left, const QVarLengthArray<T, Prealloc2> &right)
left 및 right 로 지정된 두 배열이 같지 않으면 true
를 반환합니다.
두 배열이 같은 순서로 같은 값을 포함하면 같은 배열로 간주합니다.
이 함수를 사용하려면 값 유형에 operator==()
의 구현이 있어야 합니다.
operator==()도 참조하세요 .
template <typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator<(const QVarLengthArray<T, Prealloc1> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
가변 길이 배열 lhs 이 사전적으로 rhs보다 작으면 true
을 반환하고, 그렇지 않으면 false
을 반환합니다.
이 함수를 사용하려면 값 유형에 operator<()
의 구현이 있어야 합니다.
template <typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator<=(const QVarLengthArray<T, Prealloc1> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
가변 길이 배열 lhs 이 사전적으로 rhs보다 작 거나 같으면 true
을 반환하고, 그렇지 않으면 false
을 반환합니다.
이 함수를 사용하려면 값 유형이 operator<()
의 구현을 가져야 합니다.
template <typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator==(const QVarLengthArray<T, Prealloc1> &left, const QVarLengthArray<T, Prealloc2> &right)
left 과 right 로 지정된 두 배열이 같으면 true
을 반환합니다.
두 배열이 같은 순서로 같은 값을 포함하면 같은 배열로 간주됩니다.
이 함수를 사용하려면 값 유형에 operator==()
의 구현이 있어야 합니다.
operator!=()도 참조하세요 .
template <typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator>(const QVarLengthArray<T, Prealloc1> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
가변 길이 배열 lhs 이 사전적으로 rhs보다 크면 true
을 반환하고, 그렇지 않으면 false
을 반환합니다.
이 함수를 사용하려면 값 유형에 operator<()
의 구현이 있어야 합니다.
template <typename T, qsizetype Prealloc1, qsizetype Prealloc2> bool operator>=(const QVarLengthArray<T, Prealloc1> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
가변 길이 배열 lhs 이 사전적으로 rhs보다 크거나 같으면 true
을 반환하고, 그렇지 않으면 false
을 반환합니다.
이 함수를 사용하려면 값 유형이 operator<()
의 구현을 가져야 합니다.
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.