clang-format

This commit is contained in:
Hans Dembinski 2018-03-10 22:51:54 +01:00
parent 460b417338
commit 5a546b0971
14 changed files with 179 additions and 177 deletions

View File

@ -154,8 +154,12 @@ public:
const_iterator begin() const { return const_iterator(*this, 0); }
const_iterator end() const { return const_iterator(*this, size()); }
const_reverse_iterator rbegin() const { return const_reverse_iterator(*this, size()); }
const_reverse_iterator rend() const { return const_reverse_iterator(*this, 0); }
const_reverse_iterator rbegin() const {
return const_reverse_iterator(*this, size());
}
const_reverse_iterator rend() const {
return const_reverse_iterator(*this, 0);
}
private:
friend class ::boost::serialization::access;

View File

@ -10,8 +10,8 @@
#include <algorithm>
#include <boost/bimap.hpp>
#include <boost/histogram/axis/iterator.hpp>
#include <boost/histogram/interval.hpp>
#include <boost/histogram/detail/meta.hpp>
#include <boost/histogram/interval.hpp>
#include <boost/math/constants/constants.hpp>
#include <boost/utility/string_view.hpp>
#include <cmath>
@ -37,8 +37,7 @@ namespace axis {
enum class uoflow { off = false, on = true };
/// Base class for all axes, uses CRTP.
template <typename Derived>
class axis_base {
template <typename Derived> class axis_base {
public:
using const_iterator = iterator_over<Derived>;
using const_reverse_iterator = reverse_iterator_over<Derived>;
@ -54,10 +53,18 @@ public:
/// Change the label of an axis.
void label(string_view label) { label_.assign(label.begin(), label.end()); }
const_iterator begin() const noexcept { return const_iterator(*static_cast<const Derived*>(this), 0); }
const_iterator end() const noexcept { return const_iterator(*static_cast<const Derived*>(this), size()); }
const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(*static_cast<const Derived*>(this), size()); }
const_reverse_iterator rend() const noexcept { return const_reverse_iterator(*static_cast<const Derived*>(this), 0); }
const_iterator begin() const noexcept {
return const_iterator(*static_cast<const Derived *>(this), 0);
}
const_iterator end() const noexcept {
return const_iterator(*static_cast<const Derived *>(this), size());
}
const_reverse_iterator rbegin() const noexcept {
return const_reverse_iterator(*static_cast<const Derived *>(this), size());
}
const_reverse_iterator rend() const noexcept {
return const_reverse_iterator(*static_cast<const Derived *>(this), 0);
}
protected:
axis_base(unsigned n, string_view label)
@ -96,9 +103,9 @@ private:
};
/// Base class for axes with overflow/underflow bins, uses CRTP.
template <typename Derived>
class axis_base_uoflow : public axis_base<Derived> {
template <typename Derived> class axis_base_uoflow : public axis_base<Derived> {
using base_type = axis_base<Derived>;
public:
/// Returns the number of bins, including overflow/underflow.
inline int shape() const noexcept { return shape_; }
@ -189,8 +196,10 @@ private:
*/
// private inheritance from Transform wastes no space if it is stateless
template <typename RealType, typename Transform>
class regular : public axis_base_uoflow<regular<RealType, Transform>>, Transform {
class regular : public axis_base_uoflow<regular<RealType, Transform>>,
Transform {
using base_type = axis_base_uoflow<regular<RealType, Transform>>;
public:
using value_type = RealType;
using bin_type = interval<value_type>;
@ -208,8 +217,7 @@ public:
string_view label = {},
enum uoflow uo = ::boost::histogram::axis::uoflow::on,
Transform trans = Transform())
: base_type(n, label, uo), Transform(trans),
min_(trans.forward(lower)),
: base_type(n, label, uo), Transform(trans), min_(trans.forward(lower)),
delta_((trans.forward(upper) - trans.forward(lower)) / n) {
if (!(lower < upper)) {
throw std::logic_error("lower < upper required");
@ -228,7 +236,9 @@ public:
inline int index(value_type x) const noexcept {
// Optimized code
const value_type z = (this->forward(x) - min_) / delta_;
return z >= 0.0 ? (z > base_type::size() ? base_type::size() : static_cast<int>(z)) : -1;
return z >= 0.0 ? (z > base_type::size() ? base_type::size()
: static_cast<int>(z))
: -1;
}
/// Returns the starting edge of the bin.
@ -267,8 +277,10 @@ private:
* perimeter value. Therefore, there are no overflow/underflow
* bins for this axis. Binning is a O(1) operation.
*/
template <typename RealType> class circular : public axis_base<circular<RealType>> {
template <typename RealType>
class circular : public axis_base<circular<RealType>> {
using base_type = axis_base<circular<RealType>>;
public:
using value_type = RealType;
using bin_type = interval<value_type>;
@ -294,7 +306,8 @@ public:
/// Returns the bin index for the passed argument.
inline int index(value_type x) const noexcept {
const value_type z = (x - phase_) / perimeter_;
const int i = static_cast<int>(std::floor(z * base_type::size())) % base_type::size();
const int i =
static_cast<int>(std::floor(z * base_type::size())) % base_type::size();
return i + (i < 0) * base_type::size();
}
@ -327,8 +340,10 @@ private:
* Binning is a O(log(N)) operation. If speed matters and the problem
* domain allows it, prefer a regular axis, possibly with a transform.
*/
template <typename RealType> class variable : public axis_base_uoflow<variable<RealType>> {
template <typename RealType>
class variable : public axis_base_uoflow<variable<RealType>> {
using base_type = axis_base_uoflow<variable<RealType>>;
public:
using value_type = RealType;
using bin_type = interval<value_type>;
@ -341,8 +356,7 @@ public:
*/
variable(std::initializer_list<value_type> x, string_view label = {},
enum uoflow uo = ::boost::histogram::axis::uoflow::on)
: base_type(x.size() - 1, label, uo),
x_(new value_type[x.size()]) {
: base_type(x.size() - 1, label, uo), x_(new value_type[x.size()]) {
if (x.size() < 2) {
throw std::logic_error("at least two values required");
}
@ -377,7 +391,8 @@ public:
/// Returns the bin index for the passed argument.
inline int index(value_type x) const noexcept {
return std::upper_bound(x_.get(), x_.get() + base_type::size() + 1, x) - x_.get() - 1;
return std::upper_bound(x_.get(), x_.get() + base_type::size() + 1, x) -
x_.get() - 1;
}
/// Returns the starting edge of the bin.
@ -413,8 +428,10 @@ private:
* Binning is a O(1) operation. This axis operates
* faster than a regular.
*/
template <typename IntType> class integer : public axis_base_uoflow<integer<IntType>> {
template <typename IntType>
class integer : public axis_base_uoflow<integer<IntType>> {
using base_type = axis_base_uoflow<integer<IntType>>;
public:
using value_type = IntType;
using bin_type = interval<value_type>;
@ -481,6 +498,7 @@ private:
template <typename T> class category : public axis_base<category<T>> {
using map_type = bimap<T, int>;
using base_type = axis_base<category<T>>;
public:
using value_type = T;
using bin_type = T;
@ -511,7 +529,8 @@ public:
throw std::logic_error("sequence is empty");
}
template <typename Iterator, typename = ::boost::histogram::detail::is_iterator<Iterator>>
template <typename Iterator,
typename = ::boost::histogram::detail::is_iterator<Iterator>>
category(Iterator begin, Iterator end, string_view label = {})
: base_type(std::distance(begin, end), label), map_(new map_type()) {
int index = 0;

View File

@ -15,8 +15,7 @@ namespace axis {
template <typename Axis>
class iterator_over
: public iterator_facade<iterator_over<Axis>,
typename Axis::bin_type,
: public iterator_facade<iterator_over<Axis>, typename Axis::bin_type,
random_access_traversal_tag,
typename Axis::bin_type> {
public:
@ -39,30 +38,28 @@ protected:
bool equal(const iterator_over &other) const noexcept {
return &axis_ == &other.axis_ && idx_ == other.idx_;
}
typename Axis::bin_type dereference() const {
return axis_[idx_];
}
typename Axis::bin_type dereference() const { return axis_[idx_]; }
friend class ::boost::iterator_core_access;
const Axis& axis_;
const Axis &axis_;
int idx_;
};
template <typename Axis>
class reverse_iterator_over
: public iterator_facade<reverse_iterator_over<Axis>,
typename Axis::bin_type,
random_access_traversal_tag,
typename Axis::bin_type> {
: public iterator_facade<
reverse_iterator_over<Axis>, typename Axis::bin_type,
random_access_traversal_tag, typename Axis::bin_type> {
public:
explicit reverse_iterator_over(const Axis &axis, int idx) : axis_(axis), idx_(idx) {}
explicit reverse_iterator_over(const Axis &axis, int idx)
: axis_(axis), idx_(idx) {}
reverse_iterator_over(const reverse_iterator_over &) = default;
reverse_iterator_over &operator=(const reverse_iterator_over &) = default;
operator bool() const noexcept { return idx_ > 0; }
explicit operator int() const noexcept { return idx_; }
int idx() const noexcept { return idx_-1; }
int idx() const noexcept { return idx_ - 1; }
protected:
void increment() noexcept { --idx_; }
@ -74,12 +71,10 @@ protected:
bool equal(const reverse_iterator_over &other) const noexcept {
return &axis_ == &other.axis_ && idx_ == other.idx_;
}
typename Axis::bin_type dereference() const {
return axis_[idx_-1];
}
typename Axis::bin_type dereference() const { return axis_[idx_ - 1]; }
friend class ::boost::iterator_core_access;
const Axis& axis_;
const Axis &axis_;
int idx_;
};

View File

@ -36,8 +36,8 @@ template <typename T, typename = decltype(std::declval<T &>().size(),
struct requires_storage {};
template <typename T> struct has_variance_support {
template <typename U, typename = decltype(std::declval<U&>().value(),
std::declval<U&>().variance())>
template <typename U, typename = decltype(std::declval<U &>().value(),
std::declval<U &>().variance())>
struct SFINAE {};
template <typename U> static std::true_type Test(SFINAE<U> *);
template <typename U> static std::false_type Test(...);
@ -55,11 +55,10 @@ template <typename T, typename = decltype(std::begin(std::declval<T &>()),
std::end(std::declval<T &>()))>
struct is_sequence {};
template <typename MainVector, typename AuxVector> struct union_ :
mpl::copy_if<AuxVector,
mpl::not_<mpl::contains<MainVector, mpl::_1>>,
mpl::back_inserter<MainVector>>
{};
template <typename MainVector, typename AuxVector>
struct union_
: mpl::copy_if<AuxVector, mpl::not_<mpl::contains<MainVector, mpl::_1>>,
mpl::back_inserter<MainVector>> {};
template <typename MainVector, typename AuxVector>
using union_t = typename union_<MainVector, AuxVector>::type;

View File

@ -17,16 +17,16 @@
#include <boost/histogram/detail/utility.hpp>
#include <boost/histogram/histogram_fwd.hpp>
#include <boost/histogram/iterator.hpp>
#include <boost/histogram/storage/operators.hpp>
#include <boost/histogram/storage/array_storage.hpp>
#include <boost/histogram/storage/operators.hpp>
#include <boost/histogram/storage/weight_counter.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/count_if.hpp>
#include <boost/mpl/find_if.hpp>
#include <boost/mpl/deref.hpp>
#include <boost/mpl/empty.hpp>
#include <boost/mpl/find_if.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/deref.hpp>
#include <boost/type_index.hpp>
#include <cstddef>
#include <iterator>
@ -124,14 +124,12 @@ public:
return *this;
}
template <typename T>
histogram &operator*=(const T& rhs) {
template <typename T> histogram &operator*=(const T &rhs) {
storage_ *= rhs;
return *this;
}
template <typename T>
histogram &operator/=(const T& rhs) {
template <typename T> histogram &operator/=(const T &rhs) {
storage_ *= 1.0 / rhs;
return *this;
}
@ -145,7 +143,7 @@ public:
"more than one weight argument is not allowed");
static_assert(n_sample::value <= 1,
"more than one sample argument is not allowed");
if (dim() != sizeof...(args) - n_weight::value - n_sample::value)
if (dim() != sizeof...(args)-n_weight::value - n_sample::value)
throw std::invalid_argument(
"fill arguments does not match histogram dimension");
fill_impl(mpl::bool_<n_weight::value>(), mpl::bool_<n_sample::value>(),
@ -265,9 +263,7 @@ public:
return reduce_impl(b);
}
bin_iterator begin() const noexcept {
return bin_iterator(*this, storage_);
}
bin_iterator begin() const noexcept { return bin_iterator(*this, storage_); }
bin_iterator end() const noexcept { return bin_iterator(storage_); }
@ -293,9 +289,8 @@ private:
template <typename... Args>
inline void fill_impl(mpl::true_, mpl::false_, const Args &... args) {
std::size_t idx = 0, stride = 1;
typename mpl::deref<
typename mpl::find_if<mpl::vector<Args...>, detail::is_weight<mpl::_>>::type
>::type w;
typename mpl::deref<typename mpl::find_if<
mpl::vector<Args...>, detail::is_weight<mpl::_>>::type>::type w;
wxlin<0>(idx, stride, w, args...);
if (stride) {
storage_.add(idx, w);
@ -355,12 +350,11 @@ private:
}
};
template <unsigned D>
inline void xlin(std::size_t &, std::size_t &) const {}
template <unsigned D> inline void xlin(std::size_t &, std::size_t &) const {}
template <unsigned D, typename First, typename... Rest>
inline void xlin(std::size_t &idx, std::size_t &stride,
const First &first, const Rest &... rest) const {
inline void xlin(std::size_t &idx, std::size_t &stride, const First &first,
const Rest &... rest) const {
apply_visitor(xlin_visitor<First>{idx, stride, first}, axes_[D]);
xlin<D + 1>(idx, stride, rest...);
}
@ -371,15 +365,16 @@ private:
// enable_if needed, because gcc thinks the overloads are ambiguous
template <unsigned D, typename Weight, typename First, typename... Rest>
inline typename std::enable_if<!(detail::is_weight<First>::value)>::type
wxlin(std::size_t &idx, std::size_t &stride, Weight &w,
const First &first, const Rest &... rest) const {
wxlin(std::size_t &idx, std::size_t &stride, Weight &w, const First &first,
const Rest &... rest) const {
apply_visitor(xlin_visitor<First>{idx, stride, first}, axes_[D]);
wxlin<D + 1>(idx, stride, w, rest...);
}
template <unsigned D, typename Weight, typename T, typename... Rest>
inline void wxlin(std::size_t &idx, std::size_t &stride, Weight &w,
const detail::weight_t<T> &first, const Rest &... rest) const {
const detail::weight_t<T> &first,
const Rest &... rest) const {
w = first;
wxlin<D>(idx, stride, w, rest...);
}
@ -437,12 +432,12 @@ make_dynamic_histogram(Axes &&... axes) {
template <typename... Axes>
histogram<dynamic_tag, detail::union_t<axis::builtins, mpl::vector<Axes...>>,
array_storage<weight_counter<double>>>
array_storage<weight_counter<double>>>
make_dynamic_weighted_histogram(Axes &&... axes) {
return histogram<dynamic_tag,
detail::union_t<axis::builtins, mpl::vector<Axes...>>,
array_storage<weight_counter<double>>
>(std::forward<Axes>(axes)...);
array_storage<weight_counter<double>>>(
std::forward<Axes>(axes)...);
}
template <typename Storage, typename... Axes>
@ -455,8 +450,8 @@ make_dynamic_histogram_with(Axes &&... axes) {
}
template <typename Iterator, typename = detail::is_iterator<Iterator>>
histogram<dynamic_tag, detail::union_t<axis::builtins,
typename Iterator::value_type::types>>
histogram<dynamic_tag,
detail::union_t<axis::builtins, typename Iterator::value_type::types>>
make_dynamic_histogram(Iterator begin, Iterator end) {
return histogram<
dynamic_tag,
@ -465,23 +460,21 @@ make_dynamic_histogram(Iterator begin, Iterator end) {
}
template <typename Iterator, typename = detail::is_iterator<Iterator>>
histogram<dynamic_tag, detail::union_t<axis::builtins,
typename Iterator::value_type::types>,
array_storage<weight_counter<double>>>
histogram<dynamic_tag,
detail::union_t<axis::builtins, typename Iterator::value_type::types>,
array_storage<weight_counter<double>>>
make_dynamic_weighted_histogram(Iterator begin, Iterator end) {
return histogram<
dynamic_tag,
detail::union_t<axis::builtins, typename Iterator::value_type::types>,
array_storage<weight_counter<double>>>(
begin, end);
array_storage<weight_counter<double>>>(begin, end);
}
template <typename Storage, typename Iterator,
typename = detail::is_iterator<Iterator>>
histogram<
dynamic_tag,
detail::union_t<axis::builtins, typename Iterator::value_type::types>,
Storage>
histogram<dynamic_tag,
detail::union_t<axis::builtins, typename Iterator::value_type::types>,
Storage>
make_dynamic_histogram_with(Iterator begin, Iterator end) {
return histogram<
dynamic_tag,

View File

@ -9,8 +9,8 @@
#include <boost/mpl/bool.hpp>
#include <boost/mpl/vector.hpp>
#include <type_traits>
#include <string>
#include <type_traits>
namespace boost {
namespace histogram {
@ -60,8 +60,8 @@ using static_histogram = histogram<static_tag, Axes, Storage>;
namespace detail {
template <typename T> struct weight_t {
T value;
operator const T&() const { return value; }
T value;
operator const T &() const { return value; }
};
template <typename T> struct is_weight : std::false_type {};
template <typename T> struct is_weight<weight_t<T>> : std::true_type {};

View File

@ -67,9 +67,9 @@ protected:
template <typename Storage>
class bin_iterator_over
: public iterator_facade<
bin_iterator_over<Storage>, typename Storage::bin_type,
forward_traversal_tag, typename Storage::bin_type>,
: public iterator_facade<bin_iterator_over<Storage>,
typename Storage::bin_type, forward_traversal_tag,
typename Storage::bin_type>,
public detail::multi_index {
public:

View File

@ -28,9 +28,9 @@
#include <boost/histogram/storage/operators.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/count_if.hpp>
#include <boost/mpl/find_if.hpp>
#include <boost/mpl/deref.hpp>
#include <boost/mpl/empty.hpp>
#include <boost/mpl/find_if.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/vector.hpp>
#include <type_traits>
@ -193,7 +193,7 @@ public:
template <int N>
typename std::add_const<
typename fusion::result_of::value_at_c<axes_type, N>::type>::type &
axis(mpl::int_<N>) const {
axis(mpl::int_<N>) const {
static_assert(N < axes_size::value, "axis index out of range");
return fusion::at_c<N>(axes_);
}
@ -201,7 +201,7 @@ public:
/// Get N-th axis
template <int N>
typename fusion::result_of::value_at_c<axes_type, N>::type &
axis(mpl::int_<N>) {
axis(mpl::int_<N>) {
static_assert(N < axes_size::value, "axis index out of range");
return fusion::at_c<N>(axes_);
}
@ -226,12 +226,13 @@ public:
/// Returns a lower-dimensional histogram
template <int N, typename... Rest>
auto reduce_to(mpl::int_<N>, Rest...) const -> histogram<
static_tag, detail::axes_select_t<Axes, mpl::vector<mpl::int_<N>, Rest...>>,
static_tag,
detail::axes_select_t<Axes, mpl::vector<mpl::int_<N>, Rest...>>,
Storage> {
using HR =
histogram<static_tag,
detail::axes_select_t<Axes, mpl::vector<mpl::int_<N>, Rest...>>,
Storage>;
using HR = histogram<
static_tag,
detail::axes_select_t<Axes, mpl::vector<mpl::int_<N>, Rest...>>,
Storage>;
typename HR::axes_type axes;
detail::axes_assign_subset<mpl::vector<mpl::int_<N>, Rest...>>(axes, axes_);
auto hr = HR(std::move(axes));
@ -241,9 +242,7 @@ public:
return hr;
}
bin_iterator begin() const noexcept {
return bin_iterator(*this, storage_);
}
bin_iterator begin() const noexcept { return bin_iterator(*this, storage_); }
bin_iterator end() const noexcept { return bin_iterator(storage_); }
@ -269,9 +268,8 @@ private:
template <typename... Args>
inline void fill_impl(mpl::true_, mpl::false_, const Args &... args) {
std::size_t idx = 0, stride = 1;
typename mpl::deref<
typename mpl::find_if<mpl::vector<Args...>, detail::is_weight<mpl::_>>::type
>::type w;
typename mpl::deref<typename mpl::find_if<
mpl::vector<Args...>, detail::is_weight<mpl::_>>::type>::type w;
wxlin<0>(idx, stride, w, args...);
if (stride)
storage_.add(idx, w);
@ -297,12 +295,11 @@ private:
lin<D + 1>(idx, stride, rest...);
}
template <unsigned D>
inline void xlin(std::size_t &, std::size_t &) const {}
template <unsigned D> inline void xlin(std::size_t &, std::size_t &) const {}
template <unsigned D, typename First, typename... Rest>
inline void xlin(std::size_t &idx, std::size_t &stride,
const First &first, const Rest &... rest) const {
inline void xlin(std::size_t &idx, std::size_t &stride, const First &first,
const Rest &... rest) const {
detail::xlin(idx, stride, fusion::at_c<D>(axes_), first);
xlin<D + 1>(idx, stride, rest...);
}
@ -313,15 +310,16 @@ private:
// enable_if needed, because gcc thinks the overloads are ambiguous
template <unsigned D, typename Weight, typename First, typename... Rest>
inline typename std::enable_if<!(detail::is_weight<First>::value)>::type
wxlin(std::size_t &idx, std::size_t &stride, Weight &w,
const First &first, const Rest &... rest) const {
wxlin(std::size_t &idx, std::size_t &stride, Weight &w, const First &first,
const Rest &... rest) const {
detail::xlin(idx, stride, fusion::at_c<D>(axes_), first);
wxlin<D + 1>(idx, stride, w, rest...);
}
template <unsigned D, typename Weight, typename T, typename... Rest>
inline void wxlin(std::size_t &idx, std::size_t &stride, Weight &w,
const detail::weight_t<T> &first, const Rest &... rest) const {
const detail::weight_t<T> &first,
const Rest &... rest) const {
w = first;
wxlin<D>(idx, stride, w, rest...);
}
@ -358,13 +356,14 @@ make_static_histogram(Axis &&... axis) {
}
template <typename... Axis>
inline histogram<static_tag, mpl::vector<Axis...>, array_storage<weight_counter<double>>>
inline histogram<static_tag, mpl::vector<Axis...>,
array_storage<weight_counter<double>>>
make_static_weighted_histogram(Axis &&... axis) {
using h = histogram<static_tag, mpl::vector<Axis...>, array_storage<weight_counter<double>>>;
using h = histogram<static_tag, mpl::vector<Axis...>,
array_storage<weight_counter<double>>>;
return h(typename h::axes_type(std::forward<Axis>(axis)...));
}
/// static type factory with variable storage type
template <typename Storage, typename... Axis>
inline histogram<static_tag, mpl::vector<Axis...>, Storage>

View File

@ -231,9 +231,7 @@ struct bin_visitor : public static_visitor<wcount> {
wcount operator()(const array<void> & /*b*/) const { return wcount(0.0); }
wcount operator()(const array<wcount> &b) const {
return b[idx];
}
wcount operator()(const array<wcount> &b) const { return b[idx]; }
};
template <typename RHS> struct radd_visitor : public static_visitor<void> {
@ -261,9 +259,7 @@ template <typename RHS> struct radd_visitor : public static_visitor<void> {
lhs[idx] += static_cast<mp_int>(rhs);
}
void operator()(array<wcount> &lhs) const {
lhs[idx] += rhs;
}
void operator()(array<wcount> &lhs) const { lhs[idx] += rhs; }
};
template <> struct radd_visitor<mp_int> : public static_visitor<void> {
@ -287,9 +283,7 @@ template <> struct radd_visitor<mp_int> : public static_visitor<void> {
}
}
void operator()(array<mp_int> &lhs) const {
lhs[idx] += rhs;
}
void operator()(array<mp_int> &lhs) const { lhs[idx] += rhs; }
void operator()(array<wcount> &lhs) const {
lhs[idx] += static_cast<double>(rhs);
@ -316,7 +310,8 @@ template <> struct radd_visitor<wcount> : public static_visitor<void> {
void operator()(array<wcount> &lhs) const { lhs[idx] += rhs; }
};
template <> struct radd_visitor<weight_t<double>> : public static_visitor<void> {
template <>
struct radd_visitor<weight_t<double>> : public static_visitor<void> {
any_array &lhs_any;
const std::size_t idx;
const weight_t<double> rhs;
@ -408,8 +403,7 @@ public:
: buffer_(detail::array<void>(rhs.size())) {
using T = typename RHS::bin_type;
for (std::size_t i = 0, n = rhs.size(); i < n; ++i) {
apply_visitor(detail::assign_visitor<T>(buffer_, i, rhs[i]),
buffer_);
apply_visitor(detail::assign_visitor<T>(buffer_, i, rhs[i]), buffer_);
}
}
@ -421,8 +415,7 @@ public:
}
using T = typename RHS::bin_type;
for (std::size_t i = 0; i < n; ++i) {
apply_visitor(detail::assign_visitor<T>(buffer_, i, rhs[i]),
buffer_);
apply_visitor(detail::assign_visitor<T>(buffer_, i, rhs[i]), buffer_);
}
return *this;
}
@ -435,9 +428,10 @@ public:
apply_visitor(detail::increase_visitor(buffer_, i), buffer_);
}
void add(std::size_t i, const bin_type& x) {
void add(std::size_t i, const bin_type &x) {
if (x.has_trivial_variance()) {
apply_visitor(detail::radd_visitor<double>(buffer_, i, x.value()), buffer_);
apply_visitor(detail::radd_visitor<double>(buffer_, i, x.value()),
buffer_);
} else {
apply_visitor(detail::radd_visitor<bin_type>(buffer_, i, x), buffer_);
}
@ -448,8 +442,9 @@ public:
}
template <typename T> void add(std::size_t i, const detail::weight_t<T> &w) {
apply_visitor(detail::radd_visitor<detail::weight_t<double>>(buffer_, i, w.value),
buffer_);
apply_visitor(
detail::radd_visitor<detail::weight_t<double>>(buffer_, i, w.value),
buffer_);
}
bin_type operator[](std::size_t i) const {
@ -475,13 +470,13 @@ public:
// precondition: storages have same size
template <typename RHS> adaptive_storage &operator+=(const RHS &rhs) {
for (auto i = 0ul, n = size(); i < n; ++i)
apply_visitor(detail::radd_visitor<typename RHS::bin_type>(
buffer_, i, rhs[i]),
buffer_);
apply_visitor(
detail::radd_visitor<typename RHS::bin_type>(buffer_, i, rhs[i]),
buffer_);
return *this;
}
template <typename T> adaptive_storage &operator*=(const T& x) {
template <typename T> adaptive_storage &operator*=(const T &x) {
apply_visitor(detail::rmul_visitor(buffer_, x), buffer_);
return *this;
}

View File

@ -26,15 +26,13 @@ template <typename T> class array_storage {
public:
using bin_type = T;
explicit array_storage(std::size_t s) :
size_(s), array_(new bin_type[s])
{
explicit array_storage(std::size_t s) : size_(s), array_(new bin_type[s]) {
std::fill(array_.get(), array_.get() + s, bin_type(0));
}
array_storage() = default;
array_storage(const array_storage &other) :
size_(other.size()), array_(new bin_type[other.size()]) {
array_storage(const array_storage &other)
: size_(other.size()), array_(new bin_type[other.size()]) {
std::copy(other.array_.get(), other.array_.get() + size_, array_.get());
}
array_storage &operator=(const array_storage &other) {
@ -79,16 +77,13 @@ public:
array_[i] += x;
}
const bin_type& operator[](std::size_t i) const noexcept {
return array_[i];
}
const bin_type &operator[](std::size_t i) const noexcept { return array_[i]; }
template <typename U>
bool operator==(const array_storage<U> &rhs) const noexcept {
if (size_ != rhs.size_)
return false;
return std::equal(array_.get(), array_.get() + size_,
rhs.array_.get());
return std::equal(array_.get(), array_.get() + size_, rhs.array_.get());
}
template <typename S> array_storage &operator+=(const S &rhs) noexcept {

View File

@ -28,7 +28,8 @@ public:
weight_counter &operator=(const weight_counter &) = default;
weight_counter &operator=(weight_counter &&) = default;
weight_counter(const RealType& value, const RealType& variance) : w(value), w2(variance) {}
weight_counter(const RealType &value, const RealType &variance)
: w(value), w2(variance) {}
weight_counter &operator++() {
++w;
@ -71,11 +72,13 @@ public:
return !operator==(rhs);
}
template <typename T> bool operator==(const weight_counter<T> &rhs) const noexcept {
template <typename T>
bool operator==(const weight_counter<T> &rhs) const noexcept {
return w == rhs.w && w2 == rhs.w2;
}
template <typename T> bool operator!=(const weight_counter<T> &rhs) const noexcept {
template <typename T>
bool operator!=(const weight_counter<T> &rhs) const noexcept {
return !operator==(rhs);
}
@ -87,21 +90,24 @@ public:
return !operator==(rhs);
}
const RealType& value() const noexcept { return w; }
const RealType& variance() const noexcept { return w2; }
const RealType &value() const noexcept { return w; }
const RealType &variance() const noexcept { return w2; }
bool has_trivial_variance() const noexcept { return w == w2; }
// conversion
template <typename T> explicit weight_counter(const T &t) : w(static_cast<T>(t)), w2(w) {}
template <typename T>
explicit weight_counter(const T &t) : w(static_cast<T>(t)), w2(w) {}
explicit operator RealType() const {
if (!has_trivial_variance())
throw std::logic_error("cannot convert weight_counter to RealType, value and variance differ");
throw std::logic_error("cannot convert weight_counter to RealType, value "
"and variance differ");
return w;
}
template <typename T> explicit operator T() const {
if (!has_trivial_variance())
throw std::logic_error("cannot convert weight_counter to RealType, value and variance differ");
throw std::logic_error("cannot convert weight_counter to RealType, value "
"and variance differ");
return w;
}
template <typename T> weight_counter &operator=(const T &x) {

View File

@ -6,17 +6,17 @@
#include <boost/core/lightweight_test.hpp>
#include <boost/histogram/detail/axis_visitor.hpp>
#include <boost/histogram/detail/utility.hpp>
#include <boost/histogram/detail/cat.hpp>
#include <boost/histogram/detail/meta.hpp>
#include <boost/histogram/detail/utility.hpp>
#include <boost/mpl/equal.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/vector_c.hpp>
#include <boost/variant.hpp>
#include <sstream>
#include <string>
#include <vector>
#include <boost/histogram/detail/meta.hpp>
#include <boost/mpl/equal.hpp>
#include <boost/mpl/vector_c.hpp>
#include <boost/mpl/vector.hpp>
#include <type_traits>
#include <vector>
using namespace boost::mpl;
using namespace boost::histogram::detail;
@ -93,9 +93,7 @@ int main() {
}
// cat
{
BOOST_TEST_EQ(cat("foo", 1, "bar"), std::string("foo1bar"));
}
{ BOOST_TEST_EQ(cat("foo", 1, "bar"), std::string("foo1bar")); }
// unique_sorted
{
@ -109,10 +107,10 @@ int main() {
// union
{
typedef vector<int, unsigned, char> main_vector;
typedef vector<unsigned, void*> aux_vector;
typedef vector<unsigned, void *> aux_vector;
using result = union_t<main_vector, aux_vector>;
typedef vector<int, unsigned, char, void*> expected;
typedef vector<int, unsigned, char, void *> expected;
BOOST_MPL_ASSERT((equal<result, expected, std::is_same<_, _>>));
}
@ -121,26 +119,25 @@ int main() {
struct no_methods {};
struct value_method {
const double& value() const;
const double &value() const;
};
struct variance_method {
const double& variance() const;
const double &variance() const;
};
struct value_and_variance_methods {
const double& value() const;
const double& variance() const;
const double &value() const;
const double &variance() const;
};
BOOST_TEST_EQ(typename has_variance_support<no_methods>::type(),
false);
BOOST_TEST_EQ(typename has_variance_support<value_method>::type(),
false);
BOOST_TEST_EQ(typename has_variance_support<no_methods>::type(), false);
BOOST_TEST_EQ(typename has_variance_support<value_method>::type(), false);
BOOST_TEST_EQ(typename has_variance_support<variance_method>::type(),
false);
BOOST_TEST_EQ(typename has_variance_support<value_and_variance_methods>::type(),
true);
BOOST_TEST_EQ(
typename has_variance_support<value_and_variance_methods>::type(),
true);
}
return boost::report_errors();

View File

@ -4,6 +4,7 @@
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <array>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/core/lightweight_test.hpp>
@ -19,7 +20,6 @@
#include <limits>
#include <sstream>
#include <vector>
#include <array>
using namespace boost::histogram;
using namespace boost::histogram::literals; // to get _c suffix
@ -852,8 +852,8 @@ int main() {
// using iterator ranges
{
auto h = make_dynamic_histogram(axis::integer<>(0, 2),
axis::integer<>(2, 4));
auto h =
make_dynamic_histogram(axis::integer<>(0, 2), axis::integer<>(2, 4));
auto v = std::vector<int>(2);
auto i = std::array<int, 2>();

View File

@ -34,7 +34,7 @@ int main() {
w += weight(2);
BOOST_TEST_EQ(w.value(), 3);
BOOST_TEST_EQ(w.variance(), 5);
BOOST_TEST_EQ(w.variance(), 5);
}
{
@ -43,7 +43,7 @@ int main() {
wcount u(0);
u += weight(1);
u *= 2;
BOOST_TEST_EQ(u, wcount(2, 4));
BOOST_TEST_EQ(u, wcount(2, 4));
wcount v(0);
v += weight(2);