typeid.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright Daniel Wallin 2008. Use, modification and distribution is
  2. // subject to the Boost Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #ifndef LUABIND_TYPEID_081227_HPP
  5. # define LUABIND_TYPEID_081227_HPP
  6. # include <boost/operators.hpp>
  7. # include <typeinfo>
  8. # include <luabind/detail/primitives.hpp>
  9. namespace luabind {
  10. # ifdef BOOST_MSVC
  11. # pragma warning(push)
  12. // std::type_info::before() returns int, rather than bool.
  13. // At least on MSVC7.1, this is true for the comparison
  14. // operators as well.
  15. # pragma warning(disable:4800)
  16. # endif
  17. class type_id
  18. : public boost::less_than_comparable<type_id>
  19. {
  20. public:
  21. type_id()
  22. : id(&typeid(detail::null_type))
  23. {}
  24. type_id(std::type_info const& id)
  25. : id(&id)
  26. {}
  27. bool operator!=(type_id const& other) const
  28. {
  29. return *id != *other.id;
  30. }
  31. bool operator==(type_id const& other) const
  32. {
  33. return *id == *other.id;
  34. }
  35. bool operator<(type_id const& other) const
  36. {
  37. return id->before(*other.id);
  38. }
  39. char const* name() const
  40. {
  41. return id->name();
  42. }
  43. private:
  44. std::type_info const* id;
  45. };
  46. # ifdef BOOST_MSVC
  47. # pragma warning(pop)
  48. # endif
  49. } // namespace luabind
  50. #endif // LUABIND_TYPEID_081227_HPP