Skip to content

Modern Set Add

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Set › Set › Add

Add

Adds a value; returns false if it was already there.

Syntax

Add( byref v as T ) as boolean

Examples

#import "std/containers"
using containers

dim seen as Set( of ustring )

print seen.Add( "ada" )      '' true -- inserted
print seen.Add( "ada" )      '' false -- already there

'' Deduplicating a stream in one pass
dim as ustring names( 0 to 2 ) = { "ada", "grace", "ada" }
dim uniq as Set( of ustring )
for i as integer = 0 to ubound( names )
    if uniq.Add( names( i ) ) then print "new: " & names( i )
next

Library: Set
Category: Set
Documented under: Members

Clone this wiki locally