forked from boostorg/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset.hpp
More file actions
100 lines (63 loc) · 1.62 KB
/
set.hpp
File metadata and controls
100 lines (63 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright Fady Essam 2019. Distributed under the Boost
// Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef SET_BOOST_PYTHON_HH
#define SET_BOOST_PYTHON_HH
#include <boost/python/ssize_t.hpp>
#include <boost/python.hpp>
namespace boost {
namespace python {
namespace detail
{
struct BOOST_PYTHON_DECL set_base : object
{
void add(object_cref); // add object to set
object pop(); // remove and return item at top
void discard(object_cref x); // discard value from set
long __len__(); // length of set
void clear(); // empties set
protected:
set_base();
explicit set_base(object_cref sequence); // new set initialized from sequence's items
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(set_base, object)
private:
static detail::new_non_null_reference call(object const&);
};
}
class set : public detail::set_base
{
typedef detail::set_base base;
public:
set() {}
template <class T>
explicit set(T const& sequence)
: base(object(sequence))
{
}
template <class T>
void add(T const& x)
{
base::add(object(x));
}
object pop() { return base::pop(); }
template <class T>
void discard(T const& value)
{
base::discard(object(value));
}
void clear() { base::clear(); }
long __len__() { return base::__len__(); }
public:
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(set, base)
};
namespace converter
{
template <>
struct object_manager_traits<set>
: pytype_object_manager_traits<&PySet_Type, set>
{
};
}
}
}
#endif // !SET_BOOST_PYTHON_HH