if_else.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright David Abrahams 2002.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #include <boost/static_assert.hpp>
  6. #include <boost/python/detail/if_else.hpp>
  7. #include <boost/python/detail/type_traits.hpp>
  8. typedef char c1;
  9. typedef char c2[2];
  10. typedef char c3[3];
  11. typedef char c4[4];
  12. template <unsigned size>
  13. struct choose
  14. {
  15. typedef typename boost::python::detail::if_<
  16. (sizeof(c1) == size)
  17. >::template then<
  18. c1
  19. >::template elif<
  20. (sizeof(c2) == size)
  21. >::template then<
  22. c2
  23. >::template elif<
  24. (sizeof(c3) == size)
  25. >::template then<
  26. c3
  27. >::template elif<
  28. (sizeof(c4) == size)
  29. >::template then<
  30. c4
  31. >::template else_<void*>::type type;
  32. };
  33. int main()
  34. {
  35. BOOST_STATIC_ASSERT((boost::python::detail::is_same<choose<1>::type,c1>::value));
  36. BOOST_STATIC_ASSERT((boost::python::detail::is_same<choose<2>::type,c2>::value));
  37. BOOST_STATIC_ASSERT((boost::python::detail::is_same<choose<3>::type,c3>::value));
  38. BOOST_STATIC_ASSERT((boost::python::detail::is_same<choose<4>::type,c4>::value));
  39. BOOST_STATIC_ASSERT((boost::python::detail::is_same<choose<5>::type,void*>::value));
  40. return 0;
  41. }