Skip to content

Commit 053db4e

Browse files
committed
Add user-defined literal _a as a shortcut for
1 parent 97290f4 commit 053db4e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

include/eigenpy/fwd.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ struct has_operator_equal_impl {
196196
template <class T1, class T2 = T1>
197197
struct has_operator_equal : internal::has_operator_equal_impl<T1, T2>::type {};
198198

199+
namespace literals {
200+
/// \brief A string literal returning a boost::python::arg.
201+
///
202+
/// Using-declare this operator or do `using namespace eigenpy::literals`. Then
203+
/// `bp::arg("matrix")` can be replaced by the literal `"matrix"_a`.
204+
inline boost::python::arg operator"" _a(const char *name, std::size_t) {
205+
return boost::python::arg(name);
206+
}
207+
} // namespace literals
208+
199209
} // namespace eigenpy
200210

201211
#include "eigenpy/alignment.hpp"

unittest/user_type.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,13 @@ Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> build_matrix(int rows,
150150
template <typename Scalar>
151151
void expose_custom_type(const std::string& name) {
152152
using namespace Eigen;
153+
using eigenpy::literals::operator"" _a;
153154
namespace bp = boost::python;
154155

155156
typedef CustomType<Scalar> Type;
156157

157-
bp::class_<Type>(name.c_str(), bp::init<Scalar>(bp::arg("value")))
158-
158+
// use ""_a literal
159+
bp::class_<Type>(name.c_str(), bp::init<Scalar>("value"_a))
159160
.def(bp::self + bp::self)
160161
.def(bp::self - bp::self)
161162
.def(bp::self * bp::self)

0 commit comments

Comments
 (0)