Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
VectorSet.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4#include "../Containers/Vector.h"
5#include "ContainersExport.h"
6
7namespace SC
8{
9template <typename Value, typename Container>
10struct VectorSet;
11} // namespace SC
12
15
21template <typename Value, typename Container = SC::Vector<Value>>
23{
24 Container items;
25
27 auto size() const { return items.size(); }
28
29 [[nodiscard]] Value* begin() { return items.begin(); }
30 [[nodiscard]] const Value* begin() const { return items.begin(); }
31 [[nodiscard]] Value* end() { return items.end(); }
32 [[nodiscard]] const Value* end() const { return items.end(); }
33
35 template <typename ComparableToValue>
36 [[nodiscard]] bool contains(const ComparableToValue& value) const
37 {
38 return items.contains(value);
39 }
40
42 [[nodiscard]] bool insert(const Value& value)
43 {
44 if (items.contains(value))
45 {
46 return true;
47 }
48 return items.push_back(value);
49 }
50
52 template <typename ComparableToValue>
53 [[nodiscard]] bool remove(const ComparableToValue& value)
54 {
55 return items.remove(value);
56 }
57};
A set built on an unsorted Vector, ensuring no item duplication.
Definition VectorSet.h:23
bool contains(const ComparableToValue &value) const
Check if the given Value exists in the VectorSet.
Definition VectorSet.h:36
auto size() const
Return size of the set.
Definition VectorSet.h:27
bool insert(const Value &value)
Inserts a value in the VectorSet (if it doesn't already exists)
Definition VectorSet.h:42
bool remove(const ComparableToValue &value)
Removes a value from the VectorSet (if it exists)
Definition VectorSet.h:53