test_union.cpp 603 B

12345678910111213141516171819202122
  1. /*
  2. tests/test_class.cpp -- test py::class_ definitions and basic functionality
  3. Copyright (c) 2019 Roland Dreier <roland.dreier@gmail.com>
  4. All rights reserved. Use of this source code is governed by a
  5. BSD-style license that can be found in the LICENSE file.
  6. */
  7. #include "pybind11_tests.h"
  8. TEST_SUBMODULE(union_, m) {
  9. union TestUnion {
  10. int value_int;
  11. unsigned value_uint;
  12. };
  13. py::class_<TestUnion>(m, "TestUnion")
  14. .def(py::init<>())
  15. .def_readonly("as_int", &TestUnion::value_int)
  16. .def_readwrite("as_uint", &TestUnion::value_uint);
  17. }