マインドマップギャラリー TMap ループのトラバーサル
コード例を含む、UEC での TMap のループ トラバーサル (主に元の値の変更が含まれます)、 問題分析、 改造方法など
2024-02-01 10:23:17 に編集されましたAvatar 3 centers on the Sully family, showcasing the internal rift caused by the sacrifice of their eldest son, and their alliance with other tribes on Pandora against the external conflict of the Ashbringers, who adhere to the philosophy of fire and are allied with humans. It explores the grand themes of family, faith, and survival.
This article discusses the Easter eggs and homages in Zootopia 2 that you may have discovered. The main content includes: character and archetype Easter eggs, cinematic universe crossover Easter eggs, animal ecology and behavior references, symbol and metaphor Easter eggs, social satire and brand allusions, and emotional storylines and sequel foreshadowing.
[Zootopia Character Relationship Chart] The idealistic rabbit police officer Judy and the cynical fox conman Nick form a charmingly contrasting duo, rising from street hustlers to become Zootopia police officers!
Avatar 3 centers on the Sully family, showcasing the internal rift caused by the sacrifice of their eldest son, and their alliance with other tribes on Pandora against the external conflict of the Ashbringers, who adhere to the philosophy of fire and are allied with humans. It explores the grand themes of family, faith, and survival.
This article discusses the Easter eggs and homages in Zootopia 2 that you may have discovered. The main content includes: character and archetype Easter eggs, cinematic universe crossover Easter eggs, animal ecology and behavior references, symbol and metaphor Easter eggs, social satire and brand allusions, and emotional storylines and sequel foreshadowing.
[Zootopia Character Relationship Chart] The idealistic rabbit police officer Judy and the cynical fox conman Nick form a charmingly contrasting duo, rising from street hustlers to become Zootopia police officers!
TMap ループのトラバーサル
コード例
TMap<FVerticalCurveInfo, FVerticalCurveDatas> UVerticalCurveAlgorithm::Calculate_VerticalCurveDataMap_StartEnd( UPARAM(ref) TMap<FVerticalCurveInfo, FVerticalCurveDatas>& InVerticalCurve) { for (自動垂直曲線 : InVerticalCurve) { for (int32 i = 0; i <verticalCurve.Value.Datas.Num(); i) { if (VerticalCurve.Value.Datas[i].PointTangencyType == EPointTangencyType::PointTangency) { 垂直曲線.Value.Datas[i].Elevation_Start = 垂直曲線.値.データ[i].Elevation_PointTangency - 垂直曲線.値.データ[i].T * 垂直曲線.値.データ[i].Grade; 垂直曲線.Value.Datas[i].Elevation_End = 垂直曲線.値.データ[i].Elevation_PointTangency 垂直曲線.値.データ[i].T * 垂直曲線.値.データ[i 1].Grade; } } } InVerticalCurve を返します。 }
問題分析
このコードの目的は、参照によって渡されたパラメータの値を変更することです。ただし、コードの実行結果は変更に失敗します。
問題は for (autoverticalCurve : InVerticalCurve) ループにあります。このループでは、VerticalCurve はコピーされた要素であり、元の InVerticalCurve 内の要素への参照ではありません。したがって、VerticalCurve を変更しても、元の InVerticalCurve の要素には影響しません。
参照によって渡されるパラメーターを変更するには、範囲ベースの参照ループを使用するか、反復子を使用します。
修正方法
参照ベースのループを使用する
TMap<FVerticalCurveInfo, FVerticalCurveDatas> UVerticalCurveAlgorithm::Calculate_VerticalCurveDataMap_StartEnd( UPARAM(ref) TMap<FVerticalCurveInfo, FVerticalCurveDatas>& InVerticalCurve) { for (自動&垂直曲線:InVerticalCurve) { for (int32 i = 0; i <verticalCurve.Value.Datas.Num(); i) { if (VerticalCurve.Value.Datas[i].PointTangencyType == EPointTangencyType::PointTangency) { 垂直曲線.Value.Datas[i].Elevation_Start = 垂直曲線.値.データ[i].Elevation_PointTangency - 垂直曲線.値.データ[i].T * 垂直曲線.値.データ[i].Grade; 垂直曲線.Value.Datas[i].Elevation_End = 垂直曲線.値.データ[i].Elevation_PointTangency 垂直曲線.値.データ[i].T * 垂直曲線.値.データ[i 1].Grade; } } } InVerticalCurve を返します。 }
ここでは Auto& を使用して、VerticalCurve が元の InVerticalCurve 内の要素への参照であることを確認します。この方法で値をコピーする代わりに、VerticalCurve を変更すると、元の InVerticalCurve に影響します。
イテレータを使用する
TMap<FVerticalCurveInfo, FVerticalCurveDatas> UVerticalCurveAlgorithm::Calculate_VerticalCurveDataMap_StartEnd( UPARAM(ref) TMap<FVerticalCurveInfo, FVerticalCurveDatas>& InVerticalCurve) { for (auto It = InVerticalCurve.CreateIterator(); It; It) { for (int32 i = 0; i < It.Value().Datas.Num(); i) { if (It.Value().Datas[i].PointTangencyType == EPointTangencyType::PointTangency) { It.Value().Datas[i].Elevation_Start = It.Value().Datas[i].Elevation_PointTangency - It.Value().Datas[i].T * It.Value().Datas[i]。学年; It.Value().Datas[i].Elevation_End = It.Value().Datas[i].Elevation_PointTangency It.Value().Datas[i].T * It.Value().Datas[i 1]。学年; } } } InVerticalCurve を返します。 }
この変更例では、CreateIterator() を使用して TMap イテレータを取得し、それをループ内で使用して要素にアクセスします。このようにして、It.Value() を直接変更できるため、元の InVerticalCurve を変更できます。