diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 572714726..3fbfff38f 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -30,7 +30,7 @@ jobs: strategy: matrix: python: [3] - ubuntu: [20, 22] + ubuntu: [22, 24] steps: - uses: actions/checkout@v3 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c7546e64..1ddae3fa8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/include/eigenpy/fwd.hpp b/include/eigenpy/fwd.hpp index 2b348a70c..c0fe4c75f 100644 --- a/include/eigenpy/fwd.hpp +++ b/include/eigenpy/fwd.hpp @@ -196,6 +196,16 @@ struct has_operator_equal_impl { template struct has_operator_equal : internal::has_operator_equal_impl::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" diff --git a/unittest/user_type.cpp b/unittest/user_type.cpp index 2adbac43e..dee189001 100644 --- a/unittest/user_type.cpp +++ b/unittest/user_type.cpp @@ -150,12 +150,13 @@ Eigen::Matrix build_matrix(int rows, template void expose_custom_type(const std::string& name) { using namespace Eigen; + using eigenpy::literals::operator"" _a; namespace bp = boost::python; typedef CustomType Type; - bp::class_(name.c_str(), bp::init(bp::arg("value"))) - + // use ""_a literal + bp::class_(name.c_str(), bp::init("value"_a)) .def(bp::self + bp::self) .def(bp::self - bp::self) .def(bp::self * bp::self)