as.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright (c) 2001-2011 Hartmut Kaiser
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #if !defined(BOOST_SPIRIT_KARMA_AS_STRING_DEC_18_0644PM)
  6. #define BOOST_SPIRIT_KARMA_AS_STRING_DEC_18_0644PM
  7. #if defined(_MSC_VER)
  8. #pragma once
  9. #endif
  10. #include <boost/spirit/home/support/unused.hpp>
  11. #include <boost/spirit/home/support/attributes_fwd.hpp>
  12. ///////////////////////////////////////////////////////////////////////////////
  13. namespace boost { namespace spirit { namespace traits
  14. {
  15. ///////////////////////////////////////////////////////////////////////////
  16. // This file contains the attribute to string conversion utility. The
  17. // utility provided also accept spirit's unused_type; all no-ops. Compiler
  18. // optimization will easily strip these away.
  19. ///////////////////////////////////////////////////////////////////////////
  20. ///////////////////////////////////////////////////////////////////////////
  21. template <typename T, typename Attribute>
  22. inline typename spirit::result_of::attribute_as<T, Attribute>::type
  23. as(Attribute const& attr)
  24. {
  25. return attribute_as<T, Attribute>::call(attr);
  26. }
  27. template <typename T>
  28. inline unused_type as(unused_type)
  29. {
  30. return unused;
  31. }
  32. ///////////////////////////////////////////////////////////////////////////
  33. template <typename T, typename Attribute>
  34. inline bool valid_as(Attribute const& attr)
  35. {
  36. return attribute_as<T, Attribute>::is_valid(attr);
  37. }
  38. template <typename T>
  39. inline bool valid_as(unused_type)
  40. {
  41. return true;
  42. }
  43. }}}
  44. ///////////////////////////////////////////////////////////////////////////////
  45. namespace boost { namespace spirit { namespace result_of
  46. {
  47. template <typename T, typename Attribute>
  48. struct attribute_as
  49. : traits::attribute_as<T, Attribute>
  50. {};
  51. template <typename T>
  52. struct attribute_as<T, unused_type>
  53. {
  54. typedef unused_type type;
  55. };
  56. template <typename T>
  57. struct attribute_as<T, unused_type const>
  58. {
  59. typedef unused_type type;
  60. };
  61. }}}
  62. #endif