Skip to content

Commit 5c966b7

Browse files
committed
Make enum_<> methods return *this as rvalue
1 parent 205e982 commit 5c966b7

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

include/pybind11/pybind11.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,9 @@ template <typename Type> class enum_ {
11731173
public:
11741174
using Scalar = typename std::underlying_type<Type>::type;
11751175

1176+
enum_(const enum_&) = delete;
1177+
enum_(enum_&&) = default;
1178+
11761179
template <typename... Extra>
11771180
enum_(const handle &scope, const char *name, const Extra&... extra)
11781181
: cls(scope, name, extra...), m_entries(), m_parent(scope) {
@@ -1242,18 +1245,18 @@ template <typename Type> class enum_ {
12421245
}
12431246

12441247
/// Export enumeration entries into the parent scope
1245-
enum_& export_values() {
1248+
enum_ export_values() && {
12461249
for (const auto &kv : m_entries)
12471250
m_parent.attr(kv.first) = kv.second;
1248-
return *this;
1251+
return std::move(*this);
12491252
}
12501253

12511254
/// Add an enumeration entry
1252-
enum_& value(char const* name, Type value) {
1255+
enum_ value(char const* name, Type value) && {
12531256
auto v = pybind11::cast(value, return_value_policy::copy);
12541257
cls.attr(name) = v;
12551258
m_entries[pybind11::str(name)] = v;
1256-
return *this;
1259+
return std::move(*this);
12571260
}
12581261

12591262
/// Get the associated class object.

0 commit comments

Comments
 (0)