Programming-Idioms

Implementation
C++

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating resource.

Please try to avoid dependencies to third-party libraries and frameworks.

Implementation edit is for fixing errors and enhancing with metadata.

Instead of changing the code of the snippet, consider creating another C++ implementation.

Other implementations
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Set<T> uniques = new HashSet<>(x);
x.clear();
x.addAll(uniques);
import java.util.HashSet;
import java.util.ArrayList;
x = new ArrayList<T>(new HashSet<T>(x));
y := make(map[T]struct{}, len(x))
for _, v := range x {
	y[v] = struct{}{}
}
x2 := make([]T, 0, len(y))
for _, v := range x {
	if _, ok := y[v]; ok {
		x2 = append(x2, v)
		delete(y, v)
	}
}
x = x2
import std.algorithm;
import std.array;
x = x.sort.uniq.array;
import std.container;
import std.array;
x = redBlackTree(x)[].array;
x = list(set(x))
import Data.List (sort)
nub $ sort x
using System.Collections.Generic;
using System.Linq;
var uniques = x.Distinct().ToList();
$x = array_unique($x);
uses classes;
var
  x: TList;
begin
  for i:= x.count-1 downto 0 do
    if x.indexOf(x.items[i]) <> -1 then
      x.delete(i);
end;
x.uniq!
use List::MoreUtils 'uniq';
@x = uniq(@x);
x.sort();
x.dedup();
import java.util.HashSet;
import java.util.Iterator;
final HashSet<T> seen = new HashSet<T>();
final Iterator<T> listIt = x.iterator();
while (listIt.hasNext()) {
  final T curr = listIt.next();
  if (seen.contains(curr)) {
    listIt.remove();
  } else {
    seen.add(curr);
  }
}
seen := make(map[T]bool)
j := 0
for _, v := range x {
	if !seen[v] {
		x[j] = v
		j++
		seen[v] = true
	}
}
x = x[:j]
seen := make(map[T]bool)
j := 0
for _, v := range x {
	if !seen[v] {
		x[j] = v
		j++
		seen[v] = true
	}
}
for i := j; i < len(x); i++ {
	x[i] = nil
}
x = x[:j]
x = [...new Set(x)];
x = Array.from(new Set(x));
const seen = new Set();
x = x.filter( v => {
  if(seen.has(v))
    return false;
  seen.add(v);
  return true;
});
x = x.distinct
Enum.uniq(x)
#include <algorithm>
#include <vector>
std::sort(x.begin(), x.end());
auto last = std::unique(x.begin(), x.end());
x.erase(last, x.end());
x = x.toSet().toList()
(remove-duplicates x)
S = sets:from_list(X),
sets:to_list(S).
(distinct x)
x = x.distinct()
from collections import OrderedDict
x = list(OrderedDict(zip(x, x)))
x = x.toSet().toList();
x = x.Distinct.ToList