Combine std::tuple/std::pair logic
The std::pair caster can be written as a special case of the std::tuple
caster; this combines them via a base `tuple_caster` class (which is
essentially identical to the previous std::tuple caster).
This also removes the special empty tuple base case: returning an empty
tuple is relatively rare, and the base case still works perfectly well
even when the tuple types is an empty list.
diff --git a/tests/test_builtin_casters.cpp b/tests/test_builtin_casters.cpp
index 55269ba..6733402 100644
--- a/tests/test_builtin_casters.cpp
+++ b/tests/test_builtin_casters.cpp
@@ -85,7 +85,7 @@
m.def("tuple_passthrough", [](std::tuple<bool, std::string, int> input) {
return std::make_tuple(std::get<2>(input), std::get<1>(input), std::get<0>(input));
}, "Return a triple in reversed order");
-
+ m.def("empty_tuple", []() { return std::tuple<>(); });
// test_builtins_cast_return_none
m.def("return_none_string", []() -> std::string * { return nullptr; });
diff --git a/tests/test_builtin_casters.py b/tests/test_builtin_casters.py
index a6f9b57..32eba45 100644
--- a/tests/test_builtin_casters.py
+++ b/tests/test_builtin_casters.py
@@ -188,6 +188,7 @@
# Any sequence can be cast to a std::pair or std::tuple
assert m.pair_passthrough([True, "test"]) == ("test", True)
assert m.tuple_passthrough([True, "test", 5]) == (5, "test", True)
+ assert m.empty_tuple() == ()
assert doc(m.pair_passthrough) == """
pair_passthrough(arg0: Tuple[bool, str]) -> Tuple[str, bool]