mirror of
https://github.com/boostorg/python.git
synced 2026-01-24 18:12:43 +00:00
implemented list.sort with keyword argument support, by using args_proxy and kwds_proxy. Not a nice solution though...
[SVN r55078]
This commit is contained in:
@@ -37,8 +37,12 @@ namespace detail
|
||||
void reverse(); // reverse *IN PLACE*
|
||||
|
||||
void sort(); // sort *IN PLACE*; if given, cmpfunc(x, y) -> -1, 0, 1
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
void sort(args_proxy const &args,
|
||||
kwds_proxy const &kwds);
|
||||
#else
|
||||
void sort(object_cref cmpfunc);
|
||||
|
||||
#endif
|
||||
|
||||
protected:
|
||||
list_base(); // new list
|
||||
@@ -113,13 +117,15 @@ class list : public detail::list_base
|
||||
base::remove(object(value));
|
||||
}
|
||||
|
||||
#if PY_VERSION_HEX <= 0x03000000
|
||||
void sort() { base::sort(); }
|
||||
|
||||
|
||||
template <class T>
|
||||
void sort(T const& value)
|
||||
{
|
||||
base::sort(object(value));
|
||||
}
|
||||
#endif
|
||||
|
||||
public: // implementation detail -- for internal use only
|
||||
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(list, base)
|
||||
|
||||
@@ -132,10 +132,18 @@ void list_base::sort()
|
||||
}
|
||||
}
|
||||
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
void list_base::sort(args_proxy const &args,
|
||||
kwds_proxy const &kwds)
|
||||
{
|
||||
this->attr("sort")(args, kwds);
|
||||
}
|
||||
#else
|
||||
void list_base::sort(object_cref cmpfunc)
|
||||
{
|
||||
this->attr("sort")(cmpfunc);
|
||||
}
|
||||
#endif
|
||||
|
||||
// For some reason, moving this to the end of the TU suppresses an ICE
|
||||
// with vc6.
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <boost/python/def.hpp>
|
||||
#include <boost/python/class.hpp>
|
||||
#include <boost/python/list.hpp>
|
||||
#include <boost/python/tuple.hpp>
|
||||
#include <boost/python/dict.hpp>
|
||||
#include <boost/python/make_function.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#define BOOST_ENABLE_ASSERT_HANDLER
|
||||
@@ -114,7 +116,11 @@ void exercise(list x, object y, object print)
|
||||
print(x);
|
||||
|
||||
print("reverse sorted:");
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
x.sort(*tuple(), **dict(make_tuple(make_tuple("reverse", true))));
|
||||
#else
|
||||
x.sort(¬cmp);
|
||||
#endif
|
||||
print(x);
|
||||
|
||||
list w;
|
||||
|
||||
@@ -73,7 +73,7 @@ X(22)
|
||||
...
|
||||
|
||||
>>> y = X(42)
|
||||
>>> exercise(letters, y, printer)
|
||||
>>> exercise(letters, y, printer) #doctest: +NORMALIZE_WHITESPACE
|
||||
after append:
|
||||
['h', 'e', 'l', 'l', 'o', '.', [1, 2], X(42), 5, X(3)]
|
||||
number of X(42) instances: 1
|
||||
|
||||
Reference in New Issue
Block a user