bool.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Hartmut Kaiser
  3. Copyright (c) 2011 Bryce Lelbach
  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_TEST_QI_BOOL)
  8. #define BOOST_SPIRIT_TEST_QI_BOOL
  9. #include <boost/detail/lightweight_test.hpp>
  10. #include <boost/spirit/home/x3.hpp>
  11. #include "test.hpp"
  12. ///////////////////////////////////////////////////////////////////////////////
  13. struct backwards_bool_policies : boost::spirit::x3::bool_policies<>
  14. {
  15. // we want to interpret a 'true' spelled backwards as 'false'
  16. template <typename Iterator, typename Attribute, typename CaseCompare>
  17. static bool
  18. parse_false(Iterator& first, Iterator const& last, Attribute& attr, CaseCompare const& case_compare)
  19. {
  20. namespace spirit = boost::spirit;
  21. namespace x3 = boost::spirit::x3;
  22. if (x3::detail::string_parse("eurt", first, last, x3::unused, case_compare))
  23. {
  24. x3::traits::move_to(false, attr); // result is false
  25. return true;
  26. }
  27. return false;
  28. }
  29. };
  30. ///////////////////////////////////////////////////////////////////////////////
  31. struct test_bool_type
  32. {
  33. test_bool_type(bool b = false) : b(b) {} // provide conversion
  34. bool b;
  35. };
  36. #endif