1 // Copyright 2020 Hans Dembinski
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_TEST_DUMMY_STORAGE_HPP
8 #define BOOST_HISTOGRAM_TEST_DUMMY_STORAGE_HPP
9
10 #include <algorithm>
11 #include <array>
12 #include <boost/histogram/detail/detect.hpp>
13 #include <ostream>
14 #include <type_traits>
15
16 template <class ValueType, bool Scaleable>
17 struct dummy_storage : std::array<ValueType, 10> {
18 using base_t = std::array<ValueType, 10>;
19
20 static constexpr bool has_threading_support = false;
21 static constexpr bool scaleable =
22 Scaleable && boost::histogram::detail::has_operator_rmul<ValueType, double>::value;
23
24 std::size_t size_ = 0;
25
sizedummy_storage26 std::size_t size() const { return size_; }
27
resetdummy_storage28 void reset(std::size_t n) {
29 assert(n < this->max_size());
30 size_ = n;
31 }
32
enddummy_storage33 auto end() { return this->begin() + size(); }
enddummy_storage34 auto end() const { return this->begin() + size(); }
35
operator ==dummy_storage36 bool operator==(const dummy_storage& o) const {
37 return std::equal(this->begin(), end(), o.begin(), o.end());
38 }
39
40 template <class S = dummy_storage>
operator *=dummy_storage41 std::enable_if_t<S::scaleable, dummy_storage&> operator*=(double) {
42 // do nothing, so it works with unscalable value types for testing purposes
43 return *this;
44 }
45 };
46
47 struct unscaleable {
48 int value = 0;
operator ++unscaleable49 void operator++() { ++value; }
operator ==unscaleable50 bool operator==(const int& o) const { return value == o; }
51 };
52
operator <<(std::ostream & os,const unscaleable & x)53 inline std::ostream& operator<<(std::ostream& os, const unscaleable& x) {
54 os << x.value;
55 return os;
56 }
57
58 #endif
59