Book Image

Learning C++ by creating games with UE4

By : William Sherif
Book Image

Learning C++ by creating games with UE4

By: William Sherif

Overview of this book

Table of Contents (19 chapters)
Learning C++ by Creating Games with UE4
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
2
Variables and Memory
Index

TSet<T>


A TSet<int> variable stores a set of integers. A TSet<FString> variable. stores a set of strings. The main difference between TSet and TArray is that TSet does not allow duplicates—all the elements inside a TSet are guaranteed to be unique. A TArray variable does not mind duplicates of the same elements.

To add numbers to TSet, simply call Add. Take an example of the following declaration:

TSet<int> set;
set.Add( 1 );
set.Add( 2 );
set.Add( 3 );
set.Add( 1 );// duplicate! won't be added
set.Add( 1 );// duplicate! won't be added

This is how TSet will look, as shown in the following figure:

Duplicate entries of the same value in the TSet will not be allowed. Notice how the entries in a TSet aren't numbered, as they were in a TArray: you can't use square brackets to access an entry in TSet arrays.

Iterating a TSet

In order to look into a TSet array, you must use an iterator. You can't use square brackets notation to access the elements of a TSet:

int count = 0;	// keep...