unused.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*=============================================================================
  2. Copyright (c) 2001-2014 Joel de Guzman
  3. Copyright (c) 2001-2011 Hartmut Kaiser
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #if !defined(BOOST_SPIRIT_X3_UNUSED_APRIL_16_2006_0616PM)
  8. #define BOOST_SPIRIT_X3_UNUSED_APRIL_16_2006_0616PM
  9. #include <ostream>
  10. #include <istream>
  11. #include <boost/mpl/identity.hpp>
  12. #if defined(BOOST_MSVC)
  13. # pragma warning(push)
  14. # pragma warning(disable: 4522) // multiple assignment operators specified warning
  15. #endif
  16. ///////////////////////////////////////////////////////////////////////////////
  17. namespace boost { namespace spirit { namespace x3
  18. {
  19. struct unused_type
  20. {
  21. unused_type()
  22. {
  23. }
  24. template <typename T>
  25. unused_type(T const&)
  26. {
  27. }
  28. template <typename T>
  29. unused_type const&
  30. operator=(T const&) const
  31. {
  32. return *this;
  33. }
  34. template <typename T>
  35. unused_type&
  36. operator=(T const&)
  37. {
  38. return *this;
  39. }
  40. unused_type const&
  41. operator=(unused_type const&) const
  42. {
  43. return *this;
  44. }
  45. unused_type&
  46. operator=(unused_type const&)
  47. {
  48. return *this;
  49. }
  50. // unused_type can also masquerade as an empty context (see context.hpp)
  51. template <typename ID>
  52. unused_type get(ID) const
  53. {
  54. return {};
  55. }
  56. };
  57. auto const unused = unused_type{};
  58. inline std::ostream& operator<<(std::ostream& out, unused_type const&)
  59. {
  60. return out;
  61. }
  62. inline std::istream& operator>>(std::istream& in, unused_type&)
  63. {
  64. return in;
  65. }
  66. }}}
  67. #if defined(BOOST_MSVC)
  68. # pragma warning(pop)
  69. #endif
  70. #endif