empty.hpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2019 Henry Schreiner
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt
  5. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_HISTOGRAM_ALGORITHM_EMPTY_HPP
  7. #define BOOST_HISTOGRAM_ALGORITHM_EMPTY_HPP
  8. #include <boost/histogram/fwd.hpp>
  9. #include <boost/histogram/indexed.hpp>
  10. namespace boost {
  11. namespace histogram {
  12. namespace algorithm {
  13. /** Check to see if all histogram cells are empty. Use coverage to include or
  14. exclude the underflow/overflow bins.
  15. This algorithm has O(N) complexity, where N is the number of cells.
  16. Returns true if all cells are empty, and false otherwise.
  17. */
  18. template <class A, class S>
  19. auto empty(const histogram<A, S>& h, coverage cov) {
  20. using value_type = typename histogram<A, S>::value_type;
  21. const value_type default_value = value_type();
  22. for (auto&& ind : indexed(h, cov)) {
  23. if (*ind != default_value) { return false; }
  24. }
  25. return true;
  26. }
  27. } // namespace algorithm
  28. } // namespace histogram
  29. } // namespace boost
  30. #endif