10 #ifndef SYMBOLIC_UTILS_UNIQUE_VECTOR_H_
11 #define SYMBOLIC_UTILS_UNIQUE_VECTOR_H_
32 template<
typename T_query>
33 bool contains(
const T_query& val)
const;
39 template<
typename T_query>
40 bool insert(
const T_query& val);
47 template <
class... Args>
56 template<
typename T_query>
57 bool erase(
const T_query& val);
60 using Base = std::vector<T>;
64 UniqueVector<T>::UniqueVector(std::initializer_list<T> l) : Base(l) {
65 std::sort(Base::begin(), Base::end());
66 auto last = std::unique(Base::begin(), Base::end());
67 Base::erase(last, Base::end());
68 assert(std::is_sorted(Base::begin(), Base::end()));
72 template<
typename T_query>
74 assert(std::is_sorted(Base::begin(), Base::end()));
75 const auto it = std::lower_bound(Base::begin(), Base::end(), val);
76 return it != Base::end() && *it == val;
80 template<
typename T_query>
82 assert(std::is_sorted(Base::begin(), Base::end()));
83 const auto it = std::lower_bound(Base::begin(), Base::end(), val);
84 if (it != Base::end() && *it == val)
return false;
86 Base::emplace(it, val);
92 assert(std::is_sorted(Base::begin(), Base::end()));
93 const auto it = std::lower_bound(Base::begin(), Base::end(), val);
94 if (it != Base::end() && *it == val)
return false;
96 Base::insert(it, std::move(val));
100 template <
typename T>
101 template<
typename T_query>
103 assert(std::is_sorted(Base::begin(), Base::end()));
104 const auto it = std::lower_bound(Base::begin(), Base::end(), val);
105 if (it == Base::end() || *it != val)
return false;
112 #endif // SYMBOLIC_UTILS_UNIQUE_VECTOR_H_