Skip to content

Commit b32a02c

Browse files
authored
Merge pull request #545 from ManifoldFR/topic/add-arg-literal
Add user-defined literal `""_a` for `bp::arg`
2 parents 97290f4 + 2792847 commit b32a02c

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

.github/workflows/linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
strategy:
3131
matrix:
3232
python: [3]
33-
ubuntu: [20, 22]
33+
ubuntu: [22, 24]
3434
steps:
3535
- uses: actions/checkout@v3
3636
with:

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- Add user-defined literal ""_a for bp::arg ([#545)(https://github.com/stack-of-tasks/eigenpy/pull/545))
12+
913
### Fixed
1014

1115
- Fix handling of non sorted sparse matrix ([#538](https://github.com/stack-of-tasks/eigenpy/pull/538))

include/eigenpy/fwd.hpp

Lines changed: 10 additions & 0 deletions
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

Lines changed: 3 additions & 2 deletions
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)