Improve macro type handling for types with commas

- PYBIND11_MAKE_OPAQUE now takes ... rather than a single argument and
  expands it with __VA_ARGS__; this lets templated, comma-containing
  types get through correctly.
- Adds a new macro PYBIND11_TYPE() that lets you pass the type into a
  macro as a single argument, such as:

      PYBIND11_OVERLOAD(PYBIND11_TYPE(R<1,2>), PYBIND11_TYPE(C<3,4>), func)

  Unfortunately this only works for one macro call: to forward the
  argument on to the next macro call (without the processor breaking it
  up again) requires also adding the PYBIND11_TYPE(...) to type macro
  arguments in the PYBIND11_OVERLOAD_... macro chain.
- updated the documentation with these two changes, and use them at a couple
  places in the test suite to test that they work.
This commit is contained in:
Jason Rhinelander
2018-02-27 22:33:41 -04:00
parent ab003dbdd9
commit e88656ab45
6 changed files with 46 additions and 20 deletions

View File

@@ -207,7 +207,9 @@ TEST_SUBMODULE(virtual_functions, m) {
void f() override {
py::print("PyA.f()");
PYBIND11_OVERLOAD(void, A, f);
// This convolution just gives a `void`, but tests that PYBIND11_TYPE() works to protect
// a type containing a ,
PYBIND11_OVERLOAD(PYBIND11_TYPE(typename std::enable_if<true, void>::type), A, f);
}
};