This language bar is your friend. Select your favorite languages!

Idiom #34 Create a Set of objects

Declare and initialize a Set x containing objects of type T.

import std.container: redBlackTree;
auto x = redBlackTree!T;
var x = new Set<T>();
x := make(map[T]bool)
x := make(map[T]struct{})
import Data.Set
x = empty :: Set T
import java.util.Set;
import java.util.HashSet;
Set<T> x = new HashSet<T>();
class T(object):
    pass

x = set(T())
require 'set'
x = Set.new
use std::collections::HashSet;
let x: HashSet<T> = HashSet::new();

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org

Related idioms