unused.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 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_UNUSED_APRIL_16_2006_0616PM)
  8. #define BOOST_SPIRIT_UNUSED_APRIL_16_2006_0616PM
  9. #if defined(_MSC_VER)
  10. #pragma once
  11. #endif
  12. #include <boost/config.hpp>
  13. #include <boost/mpl/bool.hpp>
  14. ///////////////////////////////////////////////////////////////////////////////
  15. namespace boost { namespace spirit
  16. {
  17. ///////////////////////////////////////////////////////////////////////////
  18. // We do not import fusion ::unused_type anymore to avoid boost::fusion
  19. // being turned into an associate namespace for boost::spirit, as this
  20. // interferes with ADL in unexpected ways. We rather copy the full
  21. // unused_type implementation from boost::fusion.
  22. ///////////////////////////////////////////////////////////////////////////
  23. struct unused_type
  24. {
  25. BOOST_DEFAULTED_FUNCTION(unused_type(), {})
  26. template <typename T>
  27. unused_type(T const&)
  28. {
  29. }
  30. template <typename T>
  31. unused_type const&
  32. operator=(T const&) const
  33. {
  34. return *this;
  35. }
  36. template <typename T>
  37. unused_type&
  38. operator=(T const&)
  39. {
  40. return *this;
  41. }
  42. };
  43. unused_type const unused = unused_type();
  44. namespace detail
  45. {
  46. struct unused_only
  47. {
  48. unused_only(unused_type const&) {}
  49. };
  50. }
  51. template <typename Out>
  52. inline Out& operator<<(Out& out, detail::unused_only const&)
  53. {
  54. return out;
  55. }
  56. template <typename In>
  57. inline In& operator>>(In& in, unused_type&)
  58. {
  59. return in;
  60. }
  61. ///////////////////////////////////////////////////////////////////////////
  62. namespace traits
  63. {
  64. // We use this test to detect if the argument is not an unused_type
  65. template <typename T> struct not_is_unused : mpl::true_ {};
  66. template <> struct not_is_unused<unused_type> : mpl::false_ {};
  67. }
  68. }}
  69. #endif