이 페이지에서

QVarLengthArray Class

template <typename T, qsizetype Prealloc> class QVarLengthArray

QVarLengthArray 클래스는 저수준 가변 길이 배열을 제공합니다. 더 보기...

헤더: #include <QVarLengthArray>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
상속받음: QVLABase 및 QVLAStorage

참고: 이 클래스의 모든 함수는 재입력이 가능합니다.

공개 유형

공용 함수

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.12) void removeAt(qsizetype i)
(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_wrong(int n)
{
    int table[n + 1];  // WRONG
    //...
    return table[n];
}

대안은 힙에 배열을 할당하는 것입니다( new 사용):

int myfunc_correct(int n)
{
    int *table = new int[n + 1];
    //...
    int ret = table[n];
    delete[] table;
    return ret;
}

그러나 애플리케이션의 내부 루프에서 myfunc()가 매우 빈번하게 호출되는 경우, 힙 할당은 성능 저하의 주요 원인이 될 수 있습니다.

QVarLengthArray는 C++ 언어의 이러한 한계를 우회하기 위한 시도입니다. 이 함수는 스택에 일정 수의 요소를 할당하고, 배열 크기를 더 크게 조정하면 자동으로 힙을 대신 사용합니다. 스택 할당은 힙 할당보다 훨씬 빠르다는 장점이 있습니다.

예시:

int myfunc_q(int n)
{
    QVarLengthArray<int, 1024> array(n + 1);
    //...
    return array[n];
}

위의 예제에서 QVarLengthArray는 스택에 1024개의 요소를 미리 할당하고, ` n + 1 `가 1024보다 크지 않은 한 이를 사용합니다. 템플릿 매개변수 ` T `는 요소 유형을 지정하고, ` Prealloc `는 스택에 미리 할당할 요소 수를 지정합니다. 생략할 경우 ` Prealloc `는 기본적으로 256으로 설정됩니다.

QVarLengthArray의 값 유형은 할당 가능한 데이터 유형이어야 합니다. 이는 일반적으로 사용되는 대부분의 데이터 유형을 포함하지만, 예를 들어 QWidget 를 값으로 저장하는 것은 컴파일러가 허용하지 않습니다. 대신 QWidget *를 저장해야 합니다.

QVarLengthArray는 QList 와 마찬가지로 크기 조정이 가능한 배열 데이터 구조를 제공합니다. 두 클래스의 주요 차이점은 다음과 같습니다.

  • QVarLengthArray의 API는 훨씬 더 저수준이며, QList 의 일부 기능이 빠져 있습니다.
  • QVarLengthArray는 값이 기본 유형인 경우 메모리를 초기화하지 않습니다. (QList 는 항상 초기화합니다.)
  • QList xml-ph-0000@deepl.internal는 메모리 최적화를 위해 암시적 공유를 사용합니다. QVarLengthArray는 이 기능을 제공하지 않지만, 오버헤드가 줄어들어 특히 반복 횟수가 많은 루프에서 일반적으로 약간 더 나은 성능을 보여줍니다.

요약하자면, QVarLengthArray는 매우 특정한 경우에만 의미가 있는 저수준 최적화 클래스입니다. 이 클래스는 Qt 내부에서 몇 군데에서 사용되며, 고급 사용자의 편의를 위해 Qt의 공개 API에 추가되었습니다.

QList도 참조하십시오 .

멤버 유형 문서

[alias] QVarLengthArray::const_iterator

const T *에 대한 typedef입니다. STL 호환성을 위해 제공됩니다.

[alias] QVarLengthArray::const_pointer

const T *에 대한 typedef입니다. STL 호환성을 위해 제공됩니다.

[alias] QVarLengthArray::const_reference

const T &에 대한 typedef입니다. STL 호환성을 위해 제공됩니다.

[alias] QVarLengthArray::const_reverse_iterator

std::reverse_iterator<const T*> 에 대한 typedef입니다. 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*> 에 대한 typedef입니다. STL 호환성을 위해 제공됩니다.

[alias] QVarLengthArray::size_type

int에 대한 typedef입니다. STL 호환성을 위해 제공됩니다.

[alias] QVarLengthArray::value_type

T에 대한 typedef입니다. STL 호환성을 위해 제공됩니다.

멤버 함수 설명서

[noexcept] QVarLengthArray::QVarLengthArray()

초기 크기가 0인 배열을 생성합니다.

[explicit] QVarLengthArray::QVarLengthArray(qsizetype size)

size 개의 요소를 가진 배열을 생성합니다.

값의 유형이 기본 유형(예: char, int, float)이거나 포인터 유형(예: 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 의 값 유형은 T 로 변환 가능해야 합니다.

제약 조건

InputIterator 가 LegacyInputIterator의 요구 사항을 충족하는 경우에만 오버로드 해결에 참여합니다.

[explicit, since 6.4] QVarLengthArray::QVarLengthArray(qsizetype size, const T &v)

size 개의 요소를 가진 배열을 생성하며, 각 요소는 v 의 복사본으로 채워집니다.

참고: 이 생성자는 T 가 복사 생성 가능한 경우에만 사용할 수 있습니다.

이 함수는 Qt 6.4에서 도입되었습니다.

size() 및 squeeze()도 참조하십시오 .

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 일 때이 함수는 noexcept입니다.

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()의 lvalue 오버로딩과는달리 , 이미 *this 의 요소인 객체에 대한 참조를 전달하면 정의되지 않은 동작이 발생합니다:

vla.append(std::move(vla[0])); // BUG: passing an object that is already in the container

이 함수는 ` QVarLengthArray::append`을 오버로드합니다.

[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) 내의 요소 수와 같아집니다. 이 함수는 범위의 요소 수가 컨테이너의 용량을 초과하는 경우에만 메모리를 할당합니다.

두 인자 중 하나라도 *this를 가리키는 이터레이터인 경우 동작이 정의되지 않습니다.

제약 조건

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 i 는 배열 내에서 유효한 인덱스 위치여야 합니다(즉, 0 <= < ()). 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 스타일의 const 이터레이터를 반환합니다.

begin() 및 cend()도 참조하십시오 .

QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray::cend() const

배열의 마지막 항목 다음에 있는 가상의 항목을 가리키는 const STL 스타일 이터레이터를 반환합니다.

cbegin() 및 end()도 참조하십시오 .

void QVarLengthArray::clear()

배열에서 모든 요소를 제거합니다.

resize(0)과 동일합니다.

QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray::constBegin() const

배열의 첫 번째 항목을 가리키는 const STL 스타일의 이터레이터를 반환합니다.

begin() 및 constEnd()도 참조하십시오 .

const T *QVarLengthArray::constData() const

배열에 저장된 데이터에 대한 const 포인터를 반환합니다. 이 포인터를 사용하여 배열의 항목에 접근할 수 있습니다. 이 포인터는 배열이 재할당되지 않는 한 유효합니다.

이 함수는 주로 일반 C++ 배열을 매개변수로 받는 함수에 배열을 전달할 때 유용합니다.

data() 및 operator[]()도 참조하십시오 .

QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray::constEnd() const

배열의 마지막 항목 다음에 있는 가상의 항목을 가리키는 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()와 동일합니다.

isEmpty() 및 resize()도 참조하십시오 .

QVarLengthArray<T, Prealloc>::const_reverse_iterator QVarLengthArray::crbegin() const

가변 길이 배열의 첫 번째 항목을 역순으로 가리키는 STL 스타일의 const 역방향 이터레이터를 반환합니다.

begin(), rbegin(), rend()도 참조하십시오 .

QVarLengthArray<T, Prealloc>::const_reverse_iterator QVarLengthArray::crend() const

가변 길이 배열의 마지막 항목 바로 다음 위치를 가리키는, 역순으로 정렬된 STL 스타일의 const 역방향 이터레이터를 반환합니다.

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 스타일의 이터레이터를 반환합니다.

begin() 및 constEnd()도 참조하십시오 .

QVarLengthArray<T, Prealloc>::const_iterator QVarLengthArray::end() const

이것은 오버로드된 함수입니다.

QVarLengthArray<T, Prealloc>::iterator QVarLengthArray::erase(QVarLengthArray<T, Prealloc>::const_iterator pos)

이테레이터 pos 가 가리키는 요소를 벡터에서 제거하고, 벡터의 다음 요소를 가리키는 이테레이터를 반환합니다( end()일 수 있음).

insert() 및 remove()도 참조하십시오 .

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()을 확인하십시오.

last() 및 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

배열에서 ` value `가 처음 나타나는 인덱스 위치를 반환하며, 인덱스 위치 ` from`부터 앞으로 검색합니다. 일치하는 항목이 없으면 -1을 반환합니다.

이 함수를 사용하려면 값 유형에 ` operator==()`가 구현되어 있어야 합니다.

lastIndexOf() 및 contains()도 참조하십시오 .

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, qsizetype count, const T &value)

이테레이터 before 가 가리키는 항목 앞에 value 의 복사본 count 개를 삽입합니다. 삽입된 항목 중 첫 번째를 가리키는 이테레이터를 반환합니다.

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 `를 삽입합니다. 삽입된 항목을 가리키는 이테레이터를 반환합니다.

void QVarLengthArray::insert(qsizetype i, qsizetype count, const T &value)

벡터의 인덱스 위치 i 에 value 의 count 개 복사본을 삽입합니다.

이 함수는 오버로드된 함수입니다.

bool QVarLengthArray::isEmpty() const

배열의 크기가 0이면 true 를 반환하고, 그렇지 않으면 false 를 반환합니다.

size() 및 resize()도 참조하십시오 .

T &QVarLengthArray::last()

배열의 마지막 항목에 대한 참조를 반환합니다. 배열은 비어 있어서는 안 됩니다. 배열이 비어 있을 수 있는 경우, 이 함수를 호출하기 전에 isEmpty()를 확인하십시오.

first() 및 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()와 동일합니다.

isEmpty() 및 resize()도 참조하십시오 .

[static constexpr noexcept, since 6.8] qsizetype QVarLengthArray::maxSize()

[constexpr noexcept, since 6.8] qsizetype QVarLengthArray::max_size() const

이 함수는 배열이 이론적으로 수용할 수 있는 최대 요소 수를 반환합니다. 실제로는 시스템에서 사용할 수 있는 메모리 양에 따라 이 수치가 훨씬 더 작을 수 있습니다.

이 함수들은 Qt 6.8에서 도입되었습니다.

void QVarLengthArray::pop_back()

removeLast()과 동일합니다. STL 호환성을 위해 제공됩니다.

void QVarLengthArray::push_back(const T &t)

t 항목을 배열에 추가하며, 필요한 경우 배열의 크기를 확장합니다. STL 호환성을 위해 제공됩니다.

void QVarLengthArray::push_back(T &&t)

참고: push_back()의 lvalue 오버로드와는달리 , 이미 ` *this `의 요소인 객체에 대한 참조를 전달하면 정의되지 않은 동작이 발생합니다:

vla.push_back(std::move(vla[0])); // BUG: passing an object that is already in the container

이 함수는 ` QVarLengthArray::push_back`을 오버로드합니다.

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 개의 요소를 제거합니다.

i i 인덱스 위치 ()이어야 합니다. 는 <= () - 이어야 합니다. == 0인 경우 == ()도 허용됩니다. size count size i count i size

insert() 및 replace()도 참조하십시오 .

[since 6.1] template <typename AT = T> qsizetype QVarLengthArray::removeAll(const AT &t)

배열에서 ` t `과 동일한 모든 요소를 제거합니다. 제거된 요소가 있는 경우, 그 개수를 반환합니다.

이 함수는 Qt 6.1에서 도입되었습니다.

removeOne()도 참조하십시오 .

[since 6.12] void QVarLengthArray::removeAt(qsizetype i)

배열에서 위치 i 에 있는 요소를 제거합니다.

i i 는 배열 내의 유효한 인덱스 위치여야 합니다(즉, 0 <= < ()). size

이 함수는 QList 과의 호환성을 위해 제공됩니다.

이 함수는 Qt 6.12에서 도입되었습니다.

insert() 및 replace()도 참조하십시오 .

[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 i 는 배열 내에서 유효한 인덱스 위치여야 합니다(즉, 0 <= < ()). size

operator[]() 및 remove()도 참조하십시오 .

void QVarLengthArray::reserve(qsizetype size)

size 개 이상의 요소에 대한 메모리를 할당하려고 시도합니다. 배열의 최대 크기를 미리 알고 있다면 이 함수를 호출할 수 있으며, resize()를 자주 호출하는 경우 더 나은 성능을 얻을 가능성이 높습니다. size 가 실제 크기보다 작게 추정된 경우, 최악의 상황에서도 QVarLengthArray 의 실행 속도가 약간 느려질 뿐입니다.

이 함수의 유일한 목적은 QVarLengthArray 의 메모리 사용량을 미세 조정할 수 있는 수단을 제공하는 것입니다. 일반적으로 이 함수를 호출해야 할 일은 거의 없습니다. 배열의 크기를 변경하려면 resize()를 호출하십시오.

capacity() 및 squeeze()도 참조하십시오 .

void QVarLengthArray::resize(qsizetype size)

배열의 크기를 ` size`로 설정합니다. ` size `가 현재 크기보다 크면 요소가 배열의 끝에 추가됩니다. ` size `가 현재 크기보다 작으면 요소가 배열의 끝에서 제거됩니다.

값의 유형이 기본 유형(예: char, int, float)이거나 포인터 유형(예: QWidget *)인 경우, 새로운 요소는 초기화되지 않습니다. 그 외의 유형의 경우, 요소는 기본 생성된 값으로 초기화됩니다.

size() 및 squeeze()도 참조하십시오 .

[since 6.4] void QVarLengthArray::resize(qsizetype size, const T &v)

배열의 크기를 ` size`로 설정합니다. ` size `가 현재 크기보다 크면, ` v `의 복사본이 배열의 끝에 추가됩니다. ` size `가 현재 크기보다 작으면, 배열의 끝에서 요소가 제거됩니다.

참고: 이 함수는 T 가 복사 생성 가능할 때만 사용할 수 있습니다.

이 함수는 Qt 6.4에서 도입되었습니다.

size() 및 squeeze()도 참조하십시오 .

void QVarLengthArray::shrink_to_fit()

squeeze()와 동일합니다. STL 호환성을 위해 제공됩니다.

qsizetype QVarLengthArray::size() const

배열에 포함된 요소의 개수를 반환합니다.

isEmpty() 및 resize()도 참조하십시오 .

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 일 때,이 함수는 noexcept입니다.

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 i 는 배열 내에서 유효한 인덱스 위치여야 합니다(즉, 0 <= < ()). size

data() 및 at()도 참조하십시오 .

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 목록에서 제거합니다. 제거된 요소가 있는 경우, 그 개수를 반환합니다. 사전 할당 크기 Prealloc 는 이 연산에 영향을 미치지 않습니다.

이 함수는 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()에서 지원되어야 합니다.

seed 를 계산의 시드로 사용하여 key 에 대한 해시 값을 반환합니다. 사전 할당 크기 Prealloc 는 해시에 영향을 미치지 않습니다.

참고: QtPrivate::QNothrowHashable_v<T> 가 true 인 경우,이 함수는 noexcept입니다.

template < typename T, qsizetype Prealloc1, qsizetype Prealloc2 > bool operator!=(const QVarLengthArray<T, Prealloc1> &left, const QVarLengthArray<T, Prealloc2> &right)

left 와 right 로 지정된 두 배열이 서로 다를 경우, true 를 반환합니다. 사전 할당된 크기인 Prealloc1 와 Prealloc2 는 서로 다를 수 있습니다.

두 배열은 동일한 순서로 동일한 값을 포함할 때 동일한 것으로 간주됩니다.

이 함수를 사용하려면 값 유형이 ` 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 을 반환합니다. 사전 할당된 크기 Prealloc1 와 Prealloc2 는 서로 다를 수 있습니다.

이 함수를 사용하려면 값 유형이 operator<() 를 구현하고 있어야 합니다.

template < typename T, qsizetype Prealloc1, qsizetype Prealloc2 > bool operator<=(const QVarLengthArray<T, Prealloc1> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)

가변 길이 배열 lhs 이 rhs보다 사전순으로 작거나 같으면 true 를 반환하고, 그렇지 않으면 false 를 반환합니다. 사전 할당된 크기 Prealloc1 와 Prealloc2 는 서로 다를 수 있습니다.

이 함수를 사용하려면 값 유형이 operator<() 를 구현하고 있어야 합니다.

template < typename T, qsizetype Prealloc1, qsizetype Prealloc2 > bool operator==(const QVarLengthArray<T, Prealloc1> &left, const QVarLengthArray<T, Prealloc2> &right)

left 와 right 로 지정된 두 배열이 같을 경우, true 을 반환합니다. 사전 할당된 크기인 Prealloc1 와 Prealloc2 는 다를 수 있습니다.

두 배열은 동일한 순서로 동일한 값을 포함할 때 동일하다고 간주됩니다.

이 함수를 사용하려면 값 유형이 ` 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 을 반환합니다. 사전 할당된 크기 Prealloc1 와 Prealloc2 은 서로 다를 수 있습니다.

이 함수를 사용하려면 값 유형이 operator<() 를 구현하고 있어야 합니다.

template < typename T, qsizetype Prealloc1, qsizetype Prealloc2 > bool operator>=(const QVarLengthArray<T, Prealloc1> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)

가변 길이 배열 lhs 이 rhs보다 사전순으로 크거나 같으면 true 을 반환하고, 그렇지 않으면 false 을 반환합니다. 사전 할당된 크기 Prealloc1 와 Prealloc2 는 서로 다를 수 있습니다.

이 함수를 사용하려면 값 유형이 ` operator<()`을 구현하고 있어야 합니다.

© 2026 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.