QLinkedList Class
template <typename T> class QLinkedListQLinkedList クラスは、リンクリストを提供するテンプレート・クラスです。詳細...
ヘッダー | #include <QLinkedList> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core5Compat) target_link_libraries(mytarget PRIVATE Qt6::Core5Compat) |
qmake: | QT += core5compat |
- 継承メンバを含む全メンバのリスト
- QLinkedListは、暗黙的に共有されるクラスの一部です。
注意:このクラスの関数はすべてリエントラントです。
パブリック型
class | const_iterator |
class | iterator |
ConstIterator | |
Iterator | |
const_pointer | |
const_reference | |
const_reverse_iterator | |
difference_type | |
pointer | |
reference | |
reverse_iterator | |
size_type | |
value_type |
パブリック関数
QLinkedList() | |
QLinkedList(std::initializer_list<T> list) | |
QLinkedList(InputIterator first, InputIterator last) | |
QLinkedList(const QLinkedList<T> &other) | |
QLinkedList(QLinkedList<T> &&other) | |
~QLinkedList() | |
void | append(const T &value) |
T & | back() |
const T & | back() const |
QLinkedList<T>::iterator | begin() |
QLinkedList<T>::const_iterator | begin() const |
QLinkedList<T>::const_iterator | cbegin() const |
QLinkedList<T>::const_iterator | cend() const |
void | clear() |
QLinkedList<T>::const_iterator | constBegin() const |
QLinkedList<T>::const_iterator | constEnd() const |
bool | contains(const T &value) const |
int | count() const |
int | count(const T &value) const |
QLinkedList<T>::const_reverse_iterator | crbegin() const |
QLinkedList<T>::const_reverse_iterator | crend() const |
bool | empty() const |
QLinkedList<T>::iterator | end() |
QLinkedList<T>::const_iterator | end() const |
bool | endsWith(const T &value) const |
QLinkedList<T>::iterator | erase(QLinkedList<T>::iterator pos) |
QLinkedList<T>::iterator | erase(QLinkedList<T>::iterator begin, QLinkedList<T>::iterator end) |
T & | first() |
const T & | first() const |
T & | front() |
const T & | front() const |
QLinkedList<T>::iterator | insert(QLinkedList<T>::iterator before, const T &value) |
bool | isEmpty() const |
T & | last() |
const T & | last() const |
void | pop_back() |
void | pop_front() |
void | prepend(const T &value) |
void | push_back(const T &value) |
void | push_front(const T &value) |
QLinkedList<T>::reverse_iterator | rbegin() |
QLinkedList<T>::const_reverse_iterator | rbegin() const |
int | removeAll(const T &value) |
void | removeFirst() |
void | removeLast() |
bool | removeOne(const T &value) |
QLinkedList<T>::reverse_iterator | rend() |
QLinkedList<T>::const_reverse_iterator | rend() const |
int | size() const |
bool | startsWith(const T &value) const |
void | swap(QLinkedList<T> &other) |
T | takeFirst() |
T | takeLast() |
std::list<T> | toStdList() const |
bool | operator!=(const QLinkedList<T> &other) const |
QLinkedList<T> | operator+(const QLinkedList<T> &other) const |
QLinkedList<T> & | operator+=(const QLinkedList<T> &other) |
QLinkedList<T> & | operator+=(const T &value) |
QLinkedList<T> & | operator<<(const QLinkedList<T> &other) |
QLinkedList<T> & | operator<<(const T &value) |
QLinkedList<T> & | operator=(const QLinkedList<T> &other) |
bool | operator==(const QLinkedList<T> &other) const |
静的パブリック・メンバー
QLinkedList<T> | fromStdList(const std::list<T> &list) |
関連する非メンバー
QDataStreamIfHasOStreamOperatorsContainer<QLinkedList<T>, T> | operator<<(QDataStream &out, const QLinkedList<T> &list) |
QDataStreamIfHasIStreamOperatorsContainer<QLinkedList<T>, T> | operator>>(QDataStream &in, QLinkedList<T> &list) |
詳しい説明
QLinkedList<T>はQtの汎用コンテナクラスの1つです。値のリストを格納し、イテレータベースのアクセスと定数時間での挿入と削除を提供します。
QList<T> と QLinkedList<T> は同様の機能を提供します。以下はその概要です:
- ほとんどの目的には、QList を使用するのが適切です。そのインデックス・ベースのAPIは、QLinkedListのイテレータ・ベースのAPIよりも便利です。そのアイテムは隣接するメモリー位置を占めます。また、実行ファイル内のコードも少なくて済む。
- リストの途中への挿入が一定時間保証され、インデックスではなくアイテムへのイテレータを持つ、本物のリンクリストが必要な場合は、QLinkedListを使用してください。
以下は整数を格納するQLinkedListと、QTime 値を格納するQLinkedListの例です:
QLinkedList<int> integerList; QLinkedList<QTime> timeList;
QLinkedList は項目のリストを格納します。デフォルトのコンストラクタは空のリストを作成します。リストに項目を挿入するには operator<<() を使用します:
QLinkedList<QString> list; list << "one" << "two" << "three"; // list: ["one", "two", "three"]
リンクされたリストの最初または最後の項目を取得するには、first() またはlast() を使用します。リストのどちらかの端から項目を削除したい場合は、removeFirst ()またはremoveLast ()を使用します。リスト内の指定された値をすべて削除したい場合は、removeAll() を使用します。
よくある要件は、リストの最初または最後の項目を削除して、それを使って何かを行うことです。このために、QLinkedList はtakeFirst() とtakeLast() を提供しています。以下は、リストから項目を1つずつ削除し、delete
を呼び出すループです:
QLinkedList<QWidget *> list; ... while (!list.isEmpty()) delete list.takeFirst();
QLinkedListの値型は、代入可能なデータ型でなければなりません。QLinkedListの値型は、代入可能なデータ型でなければなりません。これは、一般的に使用されるほとんどのデータ型をカバーしていますが、コンパイラーは、例えば、値としてQWidgetを格納することを許可しません。例えば、contains ()とremoveAll ()は、値の型がoperator==()
をサポートしている必要があります。これらの要件は、関数ごとに文書化されています。
リストの途中の項目を挿入、変更、削除したい場合は、イテレータを使用する必要があります。QLinkedList は、Java スタイルのイテレータ(QLinkedListIterator とQMutableLinkedListIterator) とSTL スタイルのイテレータ(QLinkedList::const_iterator とQLinkedList::iterator) の両方を提供しています。詳細については、これらのクラスのドキュメントを参照してください。
QLinkedListIterator,QMutableLinkedListIterator,QListも参照してください 。
メンバ型のドキュメント
QLinkedList::ConstIterator
Qt-style synonym forQLinkedList::const_iterator.
QLinkedList::Iterator
Qt-style synonym forQLinkedList::iterator.
QLinkedList::const_pointer
const T * の型定義。STL との互換性のために提供される。
QLinkedList::const_reference
const T & の型定義。STL との互換性のために提供される。
QLinkedList::const_reverse_iterator
QLinkedList::const_reverse_iterator typedef は、QLinkedList に対する STL スタイルの const 逆イテレータを提供する。
これは単にstd::reverse_iterator<QLinkedList::const_iterator>
の型定義です.
警告. 暗黙的に共有されたコンテナ上のイテレータは,STLイテレータのようには動作しない.そのコンテナ上でイテレータがアクティブになっている間は、コンテナのコピーは避けるべきである。詳細については、暗黙的共有イテレータの問題を参照してください。
QLinkedList::rbegin()、QLinkedList::rend()、QLinkedList::reverse_iterator 、QLinkedList::const_iteratorも参照のこと 。
QLinkedList::difference_type
ptrdiff_tの型定義。STL との互換性のために提供される。
QLinkedList::pointer
T * の型定義。STL との互換性のために提供される。
QLinkedList::reference
T & の型定義。STL との互換性のために提供される。
QLinkedList::reverse_iterator
QLinkedList::reverse_iterator typedef は、QLinkedList に対する STL スタイルの非 const 逆イテレータを提供する。
これは単にstd::reverse_iterator<QLinkedList::iterator>
の typedef です.
警告. 暗黙的に共有されたコンテナ上のイテレータは、STLイテレータのようには動作しません。そのコンテナ上でイテレータがアクティブになっている間は、コンテナのコピーは避けるべきである。詳細については、暗黙的共有イテレータの問題を参照してください。
QLinkedList::rbegin()、QLinkedList::rend()、QLinkedList::const_reverse_iterator 、QLinkedList::iteratorも参照のこと 。
QLinkedList::size_type
int の型定義。STL との互換性のために提供される。
QLinkedList::value_type
STL との互換性のために提供される。
メンバ関数ドキュメント
[noexcept]
QLinkedList::QLinkedList()
空のリストを作成します。
QLinkedList::QLinkedList(std::initializer_list<T> list)
list で指定された std::initializer_list からリストを構築します。
このコンストラクタは、コンパイラが C++11 のイニシャライザ リストをサポートしている場合にのみ有効になります。
template <typename InputIterator, QtPrivate::IfIsInputIterator<InputIterator> = true> QLinkedList::QLinkedList(InputIterator first, InputIterator last)
イテレータ範囲 [first,last] 内の内容を持つリストを構築する。
InputIterator
の値型はT
に変換可能でなければなりません。
QLinkedList::QLinkedList(const QLinkedList<T> &other)
other のコピーを構築する。
QLinkedListは暗黙的に共有されるため、この操作は一定時間で行われる。これにより、関数からQLinkedListを返すのが非常に高速になります。共有インスタンスが変更されると、コピーされます(コピーオンライト)。
operator=()も参照してください 。
[noexcept]
QLinkedList::QLinkedList(QLinkedList<T> &&other)
Move-QLinkedListインスタンスを構築し、other が指していたのと同じオブジェクトを指すようにする。
QLinkedList::~QLinkedList()
リストを破棄する。リスト内の値への参照、およびこのリストに対するすべてのイテレータは無効になります。
void QLinkedList::append(const T &value)
value をリストの最後に挿入する。
例
QLinkedList<QString> list; list.append("one"); list.append("two"); list.append("three"); // list: ["one", "two", "three"]
これは list.insert(end(),value) と同じ。
operator<<(),prepend(),insert()も参照 。
T &QLinkedList::back()
この関数は STL との互換性のために提供されている。last() と同等です。
const T &QLinkedList::back() const
これはオーバーロードされた関数である。
QLinkedList<T>::iterator QLinkedList::begin()
リストの最初の項目を指すSTL 形式のイテレータを返します。
constBegin() およびend()も参照して ください。
[noexcept]
QLinkedList<T>::const_iterator QLinkedList::begin() const
これはオーバーロードされた関数である。
[noexcept]
QLinkedList<T>::const_iterator QLinkedList::cbegin() const
リストの最初の項目を指すSTL 形式のイテレータを返します。
[noexcept]
QLinkedList<T>::const_iterator QLinkedList::cend() const
リストの最後の項目の後にある架空の項目を指すSTL 形式のイテレータを返します。
void QLinkedList::clear()
リスト内のすべての項目を削除します。
removeAll()も参照してください 。
[noexcept]
QLinkedList<T>::const_iterator QLinkedList::constBegin() const
リストの最初の項目を指すSTL 形式のイテレータを返します。
begin() およびconstEnd()も参照してください 。
[noexcept]
QLinkedList<T>::const_iterator QLinkedList::constEnd() const
リストの最後の項目の後にある架空の項目を指すSTL 形式のイテレータを返します。
constBegin() およびend()も参照 。
bool QLinkedList::contains(const T &value) const
リストにvalue が含まれていればtrue
を返し、そうでなければfalse
を返す。
この関数は、値型がoperator==()
を実装している必要があります。
QLinkedListIterator::findNext() およびQLinkedListIterator::findPrevious()も参照 。
int QLinkedList::count() const
size() と同じ。
int QLinkedList::count(const T &value) const
リスト内のvalue の出現回数を返す。
この関数は、値型がoperator==()
を実装している必要があります。
contains()も参照 。
[noexcept]
QLinkedList<T>::const_reverse_iterator QLinkedList::crbegin() const
リストの最初の項目を指す constSTL 形式の逆順イテレータを返します。
begin()、rbegin() およびrend()も参照してください 。
[noexcept]
QLinkedList<T>::const_reverse_iterator QLinkedList::crend() const
リストの最後の項目から逆順に1つ前の項目を指す constSTL 形式の逆順イテレータを返します。
end()、rend() およびrbegin()も参照して ください。
bool QLinkedList::empty() const
この関数はSTL互換のために用意されている。これはisEmpty() と等価であり、リストが空の場合はtrue
を返す。
QLinkedList<T>::iterator QLinkedList::end()
リストの最後の項目の後の架空の項目を指すSTL 形式のイテレータを返します。
[noexcept]
QLinkedList<T>::const_iterator QLinkedList::end() const
これはオーバーロードされた関数である。
bool QLinkedList::endsWith(const T &value) const
リストが空でなく、最後の項目がvalue に等しい場合はtrue
を返し、そうでない場合はfalse
を返す。
QLinkedList<T>::iterator QLinkedList::erase(QLinkedList<T>::iterator pos)
イテレータpos が指す項目をリストから削除し、リストの次の項目(end() かもしれない)へのイテレータを返します。
insert()も参照してください 。
QLinkedList<T>::iterator QLinkedList::erase(QLinkedList<T>::iterator begin, QLinkedList<T>::iterator end)
これはオーバーロードされた関数である。
begin からend までのすべての項目を削除します。
T &QLinkedList::first()
リストの最初の項目への参照を返します。この関数は、リストが空でないことを前提としています。
const T &QLinkedList::first() const
これはオーバーロードされた関数である。
[static]
QLinkedList<T> QLinkedList::fromStdList(const std::list<T> &list)
list に含まれるデータを持つQLinkedList オブジェクトを返す。QLinkedList の要素の順序はlist と同じです。
例:
std::list<double> stdlist; list.push_back(1.2); list.push_back(0.5); list.push_back(3.14); QLinkedList<double> list = QLinkedList<double>::fromStdList(stdlist);
toStdList()も参照 。
T &QLinkedList::front()
この関数は STL との互換性のために提供されている。first() と同等です。
const T &QLinkedList::front() const
これはオーバーロードされた関数である。
QLinkedList<T>::iterator QLinkedList::insert(QLinkedList<T>::iterator before, const T &value)
イテレータbefore が指すアイテムの前にvalue を挿入します。挿入された項目を指すイテレータを返します。
erase()も参照 。
bool QLinkedList::isEmpty() const
リストに項目がない場合はtrue
を返し、そうでない場合は false を返す。
size()も参照してください 。
T &QLinkedList::last()
リストの最後の項目への参照を返します。この関数は、リストが空でないことを前提としています。
const T &QLinkedList::last() const
これはオーバーロードされた関数である。
void QLinkedList::pop_back()
この関数は STL との互換性のために提供されている。removeLast() と同等です。
void QLinkedList::pop_front()
この関数は STL との互換性のために提供されている。removeFirst() と同等です。
void QLinkedList::prepend(const T &value)
value をリストの先頭に挿入する。
例
QLinkedList<QString> list; list.prepend("one"); list.prepend("two"); list.prepend("three"); // list: ["three", "two", "one"]
これは list.insert(begin(),value) と同じ。
void QLinkedList::push_back(const T &value)
この関数は STL との互換性のために用意されている。append(value) と同等です。
void QLinkedList::push_front(const T &value)
この関数は STL との互換性のために提供されている。prepend(value) と同等です。
QLinkedList<T>::reverse_iterator QLinkedList::rbegin()
リストの最初の項目を指すSTL 形式の逆順イテレータを返します。
[noexcept]
QLinkedList<T>::const_reverse_iterator QLinkedList::rbegin() const
これはオーバーロードされた関数である。
int QLinkedList::removeAll(const T &value)
リスト内のvalue をすべて削除する。
例
QList<QString> list; list << "sun" << "cloud" << "sun" << "rain"; list.removeAll("sun"); // list: ["cloud", "rain"]
この関数は、値型にoperator==()
の実装を必要とします。
insert()も参照してください 。
void QLinkedList::removeFirst()
リストの最初の項目を削除する。
これは erase(begin()) と同じである。
removeLast() およびerase()も参照 。
void QLinkedList::removeLast()
リストの最後の項目を削除する。
removeFirst() およびerase()も参照 。
bool QLinkedList::removeOne(const T &value)
リスト内で最初に現れるvalue を削除する。成功した場合はtrue
を返し、そうでない場合はfalse
を返す。
例
QList<QString> list; list << "sun" << "cloud" << "sun" << "rain"; list.removeOne("sun"); // list: ["cloud", "sun", "rain"]
この関数は、値型がoperator==()
を実装している必要があります。
insert()も参照してください 。
QLinkedList<T>::reverse_iterator QLinkedList::rend()
STL 形式の逆イテレータを、リストの最後の項目から逆順に 1 つ前の項目を指すように返します。
[noexcept]
QLinkedList<T>::const_reverse_iterator QLinkedList::rend() const
これはオーバーロードされた関数である。
int QLinkedList::size() const
リストに含まれる項目の数を返します。
bool QLinkedList::startsWith(const T &value) const
リストが空でなく、最初の項目がvalue に等しい場合はtrue
を返し、そうでない場合はfalse
を返す。
[noexcept]
void QLinkedList::swap(QLinkedList<T> &other)
リストother をこのリストと交換する。この操作は非常に速く、失敗することはない。
T QLinkedList::takeFirst()
リストの最初の項目を削除し、それを返す。
戻り値を使用しない場合は、removeFirst() の方が効率的です。
takeLast() およびremoveFirst()も参照 。
T QLinkedList::takeLast()
リストの最後の項目を削除して返します。
戻り値を使用しない場合は、removeLast() の方が効率的です。
takeFirst() およびremoveLast()も参照 。
std::list<T> QLinkedList::toStdList() const
このQLinkedList に含まれるデータを含む std::list オブジェクトを返します。例
QLinkedList<double> list; list << 1.2 << 0.5 << 3.14; std::list<double> stdlist = list.toStdList();
fromStdList()も参照 。
bool QLinkedList::operator!=(const QLinkedList<T> &other) const
other がこのリストと等しくない場合はtrue
を返し、そうでない場合はfalse
を返す。
2つのリストが同じ順序で同じ値を含む場合、等しいとみなされます。
この関数は、operator==()
を実装する値型を必要とします。
operator==()も参照してください 。
QLinkedList<T> QLinkedList::operator+(const QLinkedList<T> &other) const
このリストのすべての項目の後に、other のリストのすべての項目が続くリストを返します。
operator+=()も参照 。
QLinkedList<T> &QLinkedList::operator+=(const QLinkedList<T> &other)
other リストの項目をこのリストに追加し、このリストへの参照を返す。
QLinkedList<T> &QLinkedList::operator+=(const T &value)
これはオーバーロードされた関数である。
value をリストに追加する。
QLinkedList<T> &QLinkedList::operator<<(const QLinkedList<T> &other)
other リストの項目をこのリストに追加し、このリストへの参照を返す。
operator+=() およびappend()も参照 。
QLinkedList<T> &QLinkedList::operator<<(const T &value)
これはオーバーロードされた関数である。
value をリストに追加する。
QLinkedList<T> &QLinkedList::operator=(const QLinkedList<T> &other)
このリストにother を割り当て、このリストへの参照を返す。
bool QLinkedList::operator==(const QLinkedList<T> &other) const
other がこのリストと等しければtrue
を返し、そうでなければ false を返す。
2つのリストが同じ順序で同じ値を含む場合、等しいとみなされます。
この関数は、operator==()
を実装する値型を必要とします。
operator!=()も参照してください 。
関連する非会員
template <typename T> QDataStreamIfHasOStreamOperatorsContainer<QLinkedList<T>, T> operator<<(QDataStream &out, const QLinkedList<T> &list)
リンクリストlist をストリームout に書き込む。
この関数は、operator<<()
を実装する値型を必要とします。
QDataStream 演算子のフォーマットも参照してください 。
template <typename T> QDataStreamIfHasIStreamOperatorsContainer<QLinkedList<T>, T> operator>>(QDataStream &in, QLinkedList<T> &list)
リンクリストをストリームin からlist に読み込む。
この関数は、operator>>()
を実装する値型を必要とします。
QDataStream 演算子のフォーマットも参照してください 。
© 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.