Skip to content

Commit 7674c82

Browse files
committed
Fix bug with (arg("x"), "y") construct.
[SVN r21437]
1 parent b93b21a commit 7674c82

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

include/boost/python/args.hpp

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ namespace detail
4747
}
4848

4949
keyword elements[nkeywords];
50+
51+
keywords<nkeywords+1> operator,(arg const &k) const
52+
{
53+
keywords<nkeywords> const& l = *static_cast<keywords<nkeywords> const*>(this);
54+
python::detail::keywords<nkeywords+1> res;
55+
std::copy(l.elements, l.elements+nkeywords, res.elements);
56+
res.elements[nkeywords] = k.elements[0];
57+
return res;
58+
}
59+
60+
keywords<nkeywords + 1>
61+
operator,(char const *name) const
62+
{
63+
return this->operator,(python::arg(name));
64+
}
5065
};
5166

5267
template <std::size_t nkeywords>
@@ -76,15 +91,6 @@ namespace detail
7691
}
7792
};
7893

79-
template <std::size_t nkeywords>
80-
keywords<nkeywords+1> operator,(keywords<nkeywords> const& l, const keywords<1> &k)
81-
{
82-
python::detail::keywords<nkeywords+1> res;
83-
std::copy(l.elements, l.elements+nkeywords, res.elements);
84-
res.elements[nkeywords] = k.elements[0];
85-
return res;
86-
}
87-
8894
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
8995
template<typename T>
9096
struct is_keywords
@@ -136,16 +142,6 @@ namespace detail
136142
# endif
137143
}
138144

139-
namespace detail
140-
{
141-
template <std::size_t nkeywords>
142-
inline keywords<nkeywords + 1>
143-
operator,(keywords<nkeywords> const& l, char *name)
144-
{
145-
return l.operator,(arg(name));
146-
}
147-
}
148-
149145
inline detail::keywords<1> args(char const* name)
150146
{
151147
return detail::keywords<1>(name);

test/keywords.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ BOOST_PYTHON_MODULE(keywords)
9393

9494
.def("set", &Foo::set, (arg("a") = 0, arg("b") = 0.0, arg("n") = std::string()) )
9595

96+
.def("set2", &Foo::set, (arg("a"), "b", "n") )
97+
9698
.def("a", &Foo::geta)
9799
.def("b", &Foo::getb)
98100
.def("n", &Foo::getn)

test/keywords_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
>>> f.set(1,n="1")
4949
>>> f.a(), f.b(), f.n()
5050
(1, 0.0, '1')
51+
>>> f.set2(b=2.0,n="2",a=2)
52+
>>> f.a(), f.b(), f.n()
53+
(2, 2.0, '2')
5154
5255
# lets see how badly we've broken the 'regular' functions
5356
>>> f = Bar()

0 commit comments

Comments
 (0)