indexed_bit_flag.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. *
  3. * Copyright (c) 2020
  4. * John Maddock
  5. *
  6. * Use, modification and distribution are subject to the
  7. * Boost Software License, Version 1.0. (See accompanying file
  8. * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. *
  10. */
  11. /*
  12. * LOCATION: see http://www.boost.org for most recent version.
  13. * FILE basic_regex_parser.cpp
  14. * VERSION see <boost/version.hpp>
  15. * DESCRIPTION: Declares template class basic_regex_parser.
  16. */
  17. #include <boost/regex/config.hpp>
  18. #include <set>
  19. #ifndef BOOST_REGEX_V4_INDEXED_BIT_FLAG_HPP
  20. #define BOOST_REGEX_V4_INDEXED_BIT_FLAG_HPP
  21. namespace boost{
  22. namespace BOOST_REGEX_DETAIL_NS{
  23. class indexed_bit_flag
  24. {
  25. boost::uint64_t low_mask;
  26. std::set<std::size_t> mask_set;
  27. public:
  28. indexed_bit_flag() : low_mask(0) {}
  29. void set(std::size_t i)
  30. {
  31. if (i < std::numeric_limits<boost::uint64_t>::digits - 1)
  32. low_mask |= static_cast<boost::uint64_t>(1u) << i;
  33. else
  34. mask_set.insert(i);
  35. }
  36. bool test(std::size_t i)
  37. {
  38. if (i < std::numeric_limits<boost::uint64_t>::digits - 1)
  39. return low_mask & static_cast<boost::uint64_t>(1u) << i ? true : false;
  40. else
  41. return mask_set.find(i) != mask_set.end();
  42. }
  43. };
  44. } // namespace BOOST_REGEX_DETAIL_NS
  45. } // namespace boost
  46. #endif