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
7 #ifndef BOOST_HISTOGRAM_ALGORITHM_EMPTY_HPP
8 #define BOOST_HISTOGRAM_ALGORITHM_EMPTY_HPP
9
10 #include <boost/histogram/fwd.hpp>
11 #include <boost/histogram/indexed.hpp>
12
13 namespace boost {
14 namespace histogram {
15 namespace algorithm {
16 /** Check to see if all histogram cells are empty. Use coverage to include or
17 exclude the underflow/overflow bins.
18
19 This algorithm has O(N) complexity, where N is the number of cells.
20
21 Returns true if all cells are empty, and false otherwise.
22 */
23 template <class A, class S>
empty(const histogram<A,S> & h,coverage cov)24 auto empty(const histogram<A, S>& h, coverage cov) {
25 using value_type = typename histogram<A, S>::value_type;
26 const value_type default_value = value_type();
27 for (auto&& ind : indexed(h, cov)) {
28 if (*ind != default_value) { return false; }
29 }
30 return true;
31 }
32 } // namespace algorithm
33 } // namespace histogram
34 } // namespace boost
35
36 #endif
37