Py2Cpp 1.6.3; VERSION ${PROJECT_VERSION}
Loading...
Searching...
No Matches
set.hpp
Go to the documentation of this file.
1
9#pragma once
10
11#include <cstddef>
12#include <initializer_list>
13#include <unordered_set>
14// #include <utility>
15
16// template <typename T> using Value_type = typename T::value_type;
17
18namespace py {
19
28 template <typename Key> class set : public std::unordered_set<Key> {
29 using Self = set<Key>;
30 using Base = std::unordered_set<Key>;
31
32 public:
37 set() : Base{} {}
38
43 template <typename FwdIter> set(const FwdIter& start, const FwdIter& stop)
44 : Base(start, stop) {}
45
51 set(std::initializer_list<Key> init) : Base{init} {}
52
59 auto contains(const Key& key) const -> bool { return this->find(key) != this->end(); }
60
66 auto copy() const -> set { return *this; }
67
73 auto operator=(const set&) -> set& = delete;
74
80 auto operator=(set&&) noexcept -> set& = default;
81
86 set(set<Key>&&) noexcept = default;
87
92 ~set() noexcept = default;
93
94 // private:
100 set(const set<Key>&) = default;
101 };
102
111 template <typename Key> inline auto operator<(const Key& key, const set<Key>& m) -> bool {
112 return m.contains(key);
113 }
114
122 template <typename Key> inline auto len(const set<Key>& m) noexcept -> size_t {
123 return m.size();
124 }
125
131 // template <typename Key>
132 // set(std::initializer_list<Key>) -> set<Key>;
133
134 // template <typename Key>
135 // set(std::initializer_list<const char*> ) -> set<std::string>;
136} // namespace py
Python-like set implementation.
Definition set.hpp:28
auto operator=(set &&) noexcept -> set &=default
Move assignment operator.
set(std::initializer_list< Key > init)
Construct a new set object from an initializer list.
Definition set.hpp:51
auto operator=(const set &) -> set &=delete
Copy assignment operator (deleted)
auto contains(const Key &key) const -> bool
Check if the set contains a specific element.
Definition set.hpp:59
set()
Construct a new set object.
Definition set.hpp:37
auto copy() const -> set
Create a copy of the set.
Definition set.hpp:66
set(const FwdIter &start, const FwdIter &stop)
Construct a new set object.
Definition set.hpp:43
Python-like utilities and data structures for C++.
Definition dict.hpp:18
auto len(const dict< Key, T > &m) noexcept -> size_t
Get the number of key-value pairs in a dictionary.
Definition dict.hpp:284