Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
strategy:
matrix:
python: [3]
ubuntu: [20, 22]
ubuntu: [22, 24]
steps:
- uses: actions/checkout@v3
with:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### Added

- Add user-defined literal ""_a for bp::arg ([#545)(https://github.com/stack-of-tasks/eigenpy/pull/545))

### Fixed

- Fix handling of non sorted sparse matrix ([#538](https://github.com/stack-of-tasks/eigenpy/pull/538))
Expand Down
10 changes: 10 additions & 0 deletions include/eigenpy/fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@ struct has_operator_equal_impl {
template <class T1, class T2 = T1>
struct has_operator_equal : internal::has_operator_equal_impl<T1, T2>::type {};

namespace literals {
/// \brief A string literal returning a boost::python::arg.
///
/// Using-declare this operator or do `using namespace eigenpy::literals`. Then
/// `bp::arg("matrix")` can be replaced by the literal `"matrix"_a`.
inline boost::python::arg operator"" _a(const char *name, std::size_t) {
return boost::python::arg(name);
}
} // namespace literals

} // namespace eigenpy

#include "eigenpy/alignment.hpp"
Expand Down
5 changes: 3 additions & 2 deletions unittest/user_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,13 @@ Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> build_matrix(int rows,
template <typename Scalar>
void expose_custom_type(const std::string& name) {
using namespace Eigen;
using eigenpy::literals::operator"" _a;
namespace bp = boost::python;

typedef CustomType<Scalar> Type;

bp::class_<Type>(name.c_str(), bp::init<Scalar>(bp::arg("value")))

// use ""_a literal
bp::class_<Type>(name.c_str(), bp::init<Scalar>("value"_a))
.def(bp::self + bp::self)
.def(bp::self - bp::self)
.def(bp::self * bp::self)
Expand Down
Loading