clang-format

This commit is contained in:
Hans Dembinski
2017-03-28 23:27:22 +02:00
parent 493d6c7974
commit 3b31bf51df
12 changed files with 114 additions and 116 deletions

View File

@@ -23,8 +23,7 @@ template <typename T> struct has_variance {
template <typename> static std::false_type test(...);
template <typename C>
static decltype(std::declval<C &>().variance(0), std::true_type{})
test(int);
static decltype(std::declval<C &>().variance(0), std::true_type{}) test(int);
static bool const value = decltype(test<T>(0))::value;
};

View File

@@ -27,7 +27,8 @@ inline void escape(std::ostream &os, const String &s) {
}
template <typename A, typename> struct lin {
static inline void apply(std::size_t &out, std::size_t &stride, const A &a, int j) {
static inline void apply(std::size_t &out, std::size_t &stride, const A &a,
int j) {
// the following is highly optimized code that runs in a hot loop;
// please measure the performance impact of changes
const int uoflow = a.uoflow();
@@ -43,7 +44,7 @@ template <typename A, typename> struct lin {
template <typename A, typename T> struct xlin {
static inline void apply(std::size_t &out, std::size_t &stride, const A &a,
const T &x) {
const T &x) {
// the following is highly optimized code that runs in a hot loop;
// please measure the performance impact of changes
int j = a.index(x);

View File

@@ -8,7 +8,7 @@
#define _BOOST_HISTOGRAM_HISTOGRAM_HPP_
#include <boost/histogram/histogram_fwd.hpp>
#include <boost/histogram/histogram_static_impl.hpp>
#include <boost/histogram/histogram_dynamic_impl.hpp>
#include <boost/histogram/histogram_static_impl.hpp>
#endif

View File

@@ -10,11 +10,11 @@
#include <algorithm>
#include <boost/assert.hpp>
#include <boost/config.hpp>
#include <boost/histogram/histogram_fwd.hpp>
#include <boost/histogram/axis.hpp>
#include <boost/histogram/detail/axis_visitor.hpp>
#include <boost/histogram/detail/meta.hpp>
#include <boost/histogram/detail/utility.hpp>
#include <boost/histogram/histogram_fwd.hpp>
#include <boost/mpl/empty.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/variant.hpp>
@@ -31,6 +31,7 @@ template <typename Axes, typename Storage>
class histogram<true, Axes, Storage> {
static_assert(!mpl::empty<Axes>::value, "at least one axis required");
using size_pair = std::pair<std::size_t, std::size_t>;
public:
using axis_type = typename make_variant_over<Axes>::type;
using value_type = typename Storage::value_type;
@@ -42,8 +43,7 @@ public:
histogram() = default;
template <typename... Axes1>
explicit histogram(const Axes1 &... axes)
: axes_({axis_type(axes)...}) {
explicit histogram(const Axes1 &... axes) : axes_({axis_type(axes)...}) {
storage_ = Storage(field_count());
}
@@ -54,19 +54,17 @@ public:
storage_ = Storage(field_count());
}
template <typename OtherAxes, typename OtherStorage>
explicit histogram(
const histogram<true, OtherAxes, OtherStorage> &other)
template <typename A, typename S>
explicit histogram(const histogram<true, A, S> &other)
: axes_(other.axes_.begin(), other.axes_.end()),
storage_(other.storage_) {}
template <typename OtherAxes, typename OtherStorage>
explicit histogram(histogram<true, OtherAxes, OtherStorage> &&other)
template <typename A, typename S>
explicit histogram(histogram<true, A, S> &&other)
: axes_(std::move(other.axes_)), storage_(std::move(other.storage_)) {}
template <typename OtherAxes, typename OtherStorage>
histogram &
operator=(const histogram<true, OtherAxes, OtherStorage> &other) {
template <typename A, typename S>
histogram &operator=(const histogram<true, A, S> &other) {
if (static_cast<const void *>(this) != static_cast<const void *>(&other)) {
axes_ = other.axes_;
storage_ = other.storage_;
@@ -74,9 +72,8 @@ public:
return *this;
}
template <typename OtherAxes, typename OtherStorage>
histogram &
operator=(histogram<true, OtherAxes, OtherStorage> &&other) {
template <typename A, typename S>
histogram &operator=(histogram<true, A, S> &&other) {
if (static_cast<const void *>(this) != static_cast<const void *>(&other)) {
axes_ = std::move(other.axes_);
storage_ = std::move(other.storage_);
@@ -84,11 +81,10 @@ public:
return *this;
}
template <typename OtherAxes, typename OtherStorage>
bool
operator==(const histogram<true, OtherAxes, OtherStorage> &other) const {
template <typename A, typename S>
bool operator==(const histogram<true, A, S> &other) const {
if (mpl::empty<
typename detail::intersection<Axes, OtherAxes>::type>::value) {
typename detail::intersection<Axes, A>::type>::value) {
return false;
}
if (dim() != other.dim()) {
@@ -104,11 +100,9 @@ public:
}
template <bool D, typename A, typename S>
histogram &
operator+=(const histogram<D, A, S> &other) {
histogram &operator+=(const histogram<D, A, S> &other) {
static_assert(
!mpl::empty<
typename detail::intersection<Axes, A>::type>::value,
!mpl::empty<typename detail::intersection<Axes, A>::type>::value,
"histograms lack common axes types");
if (dim() != other.dim()) {
throw std::logic_error("dimensions of histograms differ");
@@ -126,7 +120,8 @@ public:
template <typename... Values> void fill(Values... values) {
BOOST_ASSERT_MSG(sizeof...(values) == dim(),
"number of arguments does not match histogram dimension");
const auto p = apply_lin<detail::xlin, Values...>(size_pair(0, 1), values...);
const auto p =
apply_lin<detail::xlin, Values...>(size_pair(0, 1), values...);
if (p.second) {
storage_.increase(p.first);
}
@@ -142,11 +137,11 @@ public:
}
}
template <typename... Values>
void wfill(value_type w, Values... values) {
template <typename... Values> void wfill(value_type w, Values... values) {
BOOST_ASSERT_MSG(sizeof...(values) == dim(),
"number of arguments does not match histogram dimension");
const auto p = apply_lin<detail::xlin, Values...>(size_pair(0, 1), values...);
const auto p =
apply_lin<detail::xlin, Values...>(size_pair(0, 1), values...);
if (p.second) {
storage_.increase(p.first, w);
}
@@ -165,7 +160,8 @@ public:
template <typename... Indices> value_type value(Indices... indices) const {
BOOST_ASSERT_MSG(sizeof...(indices) == dim(),
"number of arguments does not match histogram dimension");
const auto p = apply_lin<detail::lin, Indices...>(size_pair(0, 1), indices...);
const auto p =
apply_lin<detail::lin, Indices...>(size_pair(0, 1), indices...);
if (p.second == 0) {
throw std::out_of_range("invalid index");
}
@@ -184,10 +180,12 @@ public:
}
template <typename... Indices> value_type variance(Indices... indices) const {
static_assert(detail::has_variance<Storage>::value, "Storage lacks variance support");
static_assert(detail::has_variance<Storage>::value,
"Storage lacks variance support");
BOOST_ASSERT_MSG(sizeof...(indices) == dim(),
"number of arguments does not match histogram dimension");
const auto p = apply_lin<detail::lin, Indices...>(size_pair(0, 1), indices...);
const auto p =
apply_lin<detail::lin, Indices...>(size_pair(0, 1), indices...);
if (p.second == 0) {
throw std::out_of_range("invalid index");
}
@@ -196,7 +194,8 @@ public:
template <typename Iterator, typename = detail::is_iterator<Iterator>>
value_type variance(Iterator begin, Iterator end) const {
static_assert(detail::has_variance<Storage>::value, "Storage lacks variance support");
static_assert(detail::has_variance<Storage>::value,
"Storage lacks variance support");
BOOST_ASSERT_MSG(std::distance(begin, end) == dim(),
"number of arguments does not match histogram dimension");
const auto p = apply_lin_iter<detail::lin>(size_pair(0, 1), begin);
@@ -252,8 +251,8 @@ private:
return fc.value;
}
template <typename OtherAxes>
bool axes_equal_to(const OtherAxes &other_axes) const {
template <typename A>
bool axes_equal_to(const A &other_axes) const {
detail::cmp_axis ca;
for (unsigned i = 0; i < dim(); ++i) {
if (!apply_visitor(ca, axes_[i], other_axes[i])) {
@@ -267,8 +266,7 @@ private:
struct lin_visitor : public static_visitor<size_pair> {
mutable size_pair pa;
const Value &val;
lin_visitor(const size_pair& p, const Value &v)
: pa(p), val(v) {}
lin_visitor(const size_pair &p, const Value &v) : pa(p), val(v) {}
template <typename A> size_pair operator()(const A &a) const {
Lin<A, Value>::apply(pa.first, pa.second, a, val);
return pa;
@@ -276,18 +274,20 @@ private:
};
template <template <class, class> class Lin, typename First, typename... Rest>
size_pair apply_lin(size_pair&& p, const First &first,
const Rest &... rest) const {
size_pair apply_lin(size_pair &&p, const First &first,
const Rest &... rest) const {
p = apply_visitor(lin_visitor<Lin, First>(p, first),
axes_[dim() - 1 - sizeof...(Rest)]);
return apply_lin<Lin, Rest...>(std::move(p), rest...);
}
template <template <class, class> class Lin>
size_pair apply_lin(size_pair&& p) const { return p; }
size_pair apply_lin(size_pair &&p) const {
return p;
}
template <template <class, class> class Lin, typename Iterator>
size_pair apply_lin_iter(size_pair&& p, Iterator iter) const {
size_pair apply_lin_iter(size_pair &&p, Iterator iter) const {
for (const auto &a : axes_) {
p = apply_visitor(lin_visitor<Lin, decltype(*iter)>(p, *iter), a);
++iter;
@@ -297,12 +297,10 @@ private:
friend struct storage_access;
template <bool D, typename A, typename S>
friend class histogram;
template <bool D, typename A, typename S> friend class histogram;
template <typename Archiv, typename A, typename S>
friend void serialize(Archiv &, histogram<true, A, S> &,
unsigned);
friend void serialize(Archiv &, histogram<true, A, S> &, unsigned);
};
template <typename... Axes>

View File

@@ -10,11 +10,10 @@
#include <boost/histogram/storage/adaptive_storage.hpp>
namespace boost {
namespace histogram {
namespace histogram {
template <bool Dynamic,
class Axes,
class Storage = adaptive_storage<> > class histogram;
template <bool Dynamic, class Axes, class Storage = adaptive_storage<>>
class histogram;
} // namespace histogram
} // namespace boost

View File

@@ -25,8 +25,7 @@ struct axis_ostream_visitor {
} // namespace detail
template <bool D, typename A, typename S>
inline std::ostream &operator<<(std::ostream &os,
const histogram<D, A, S> &h) {
inline std::ostream &operator<<(std::ostream &os, const histogram<D, A, S> &h) {
os << "histogram(";
detail::axis_ostream_visitor sh(os);
h.for_each_axis(sh);

View File

@@ -18,11 +18,11 @@
#include <boost/fusion/include/sequence.hpp>
#include <boost/fusion/sequence.hpp>
#include <boost/fusion/sequence/comparison.hpp>
#include <boost/histogram/histogram_fwd.hpp>
#include <boost/histogram/axis.hpp>
#include <boost/histogram/detail/axis_visitor.hpp>
#include <boost/histogram/detail/meta.hpp>
#include <boost/histogram/detail/utility.hpp>
#include <boost/histogram/histogram_fwd.hpp>
#include <boost/histogram/storage/adaptive_storage.hpp>
#include <boost/mpl/empty.hpp>
#include <boost/mpl/vector.hpp>
@@ -36,6 +36,7 @@ class histogram<false, Axes, Storage> {
static_assert(!mpl::empty<Axes>::value, "at least one axis required");
using size_pair = std::pair<std::size_t, std::size_t>;
using axes_size = typename fusion::result_of::size<Axes>::type;
public:
using value_type = typename Storage::value_type;
@@ -64,8 +65,7 @@ public:
: axes_(std::move(other.axes_)), storage_(std::move(other.storage_)) {}
template <typename S>
histogram &
operator=(const histogram<false, Axes, S> &other) {
histogram &operator=(const histogram<false, Axes, S> &other) {
if (static_cast<const void *>(this) != static_cast<const void *>(&other)) {
axes_ = other.axes_;
storage_ = other.storage_;
@@ -83,8 +83,7 @@ public:
}
template <typename A, typename S>
bool
operator==(const histogram<false, A, S> &other) const {
bool operator==(const histogram<false, A, S> &other) const {
if (!axes_equal_to(other.axes_)) {
return false;
}
@@ -92,8 +91,7 @@ public:
}
template <typename S>
histogram &
operator+=(const histogram<false, Axes, S> &other) {
histogram &operator+=(const histogram<false, Axes, S> &other) {
if (!axes_equal_to(other.axes_)) {
throw std::logic_error("axes of histograms differ");
}
@@ -104,7 +102,8 @@ public:
template <typename... Values> void fill(Values... values) {
static_assert(sizeof...(values) == axes_size::value,
"number of arguments does not match histogram dimension");
const auto p = apply_lin<detail::xlin, Values...>(size_pair(0, 1), values...);
const auto p =
apply_lin<detail::xlin, Values...>(size_pair(0, 1), values...);
if (p.second) {
storage_.increase(p.first);
}
@@ -113,7 +112,8 @@ public:
template <typename... Values> void wfill(value_type w, Values... values) {
static_assert(sizeof...(values) == axes_size::value,
"number of arguments does not match histogram dimension");
const auto p = apply_lin<detail::xlin, Values...>(size_pair(0, 1), values...);
const auto p =
apply_lin<detail::xlin, Values...>(size_pair(0, 1), values...);
if (p.second) {
storage_.increase(p.first, w);
}
@@ -122,7 +122,8 @@ public:
template <typename... Indices> value_type value(Indices... indices) const {
static_assert(sizeof...(indices) == axes_size::value,
"number of arguments does not match histogram dimension");
const auto p = apply_lin<detail::lin, Indices...>(size_pair(0, 1), indices...);
const auto p =
apply_lin<detail::lin, Indices...>(size_pair(0, 1), indices...);
if (p.second == 0) {
throw std::out_of_range("invalid index");
}
@@ -130,10 +131,12 @@ public:
}
template <typename... Indices> value_type variance(Indices... indices) const {
static_assert(detail::has_variance<Storage>::value, "Storage lacks variance support");
static_assert(detail::has_variance<Storage>::value,
"Storage lacks variance support");
static_assert(sizeof...(indices) == axes_size::value,
"number of arguments does not match histogram dimension");
const auto p = apply_lin<detail::lin, Indices...>(size_pair(0, 1), indices...);
const auto p =
apply_lin<detail::lin, Indices...>(size_pair(0, 1), indices...);
if (p.second == 0) {
throw std::out_of_range("invalid index");
}
@@ -178,8 +181,7 @@ private:
return fc.value;
}
template <typename A>
bool axes_equal_to(const A & /*unused*/) const {
template <typename A> bool axes_equal_to(const A & /*unused*/) const {
return false;
}
@@ -188,24 +190,26 @@ private:
}
template <template <class, class> class Lin, typename First, typename... Rest>
size_pair apply_lin(size_pair&& p, const First &x,
const Rest &... rest) const {
size_pair apply_lin(size_pair &&p, const First &x,
const Rest &... rest) const {
Lin<typename fusion::result_of::value_at_c<
axes_type, (axes_size::value - 1 - sizeof...(Rest))>::type,
First>::apply(p.first, p.second,
fusion::at_c<(axes_size::value - 1 - sizeof...(Rest))>(axes_), x);
fusion::at_c<(axes_size::value - 1 - sizeof...(Rest))>(
axes_),
x);
return apply_lin<Lin, Rest...>(std::move(p), rest...);
}
template <template <class, class> class Lin>
size_pair apply_lin(size_pair&& p) const { return p; }
size_pair apply_lin(size_pair &&p) const {
return p;
}
template <bool D, typename A, typename S>
friend class histogram;
template <bool D, typename A, typename S> friend class histogram;
template <class Archive, class S, class A>
friend void serialize(Archive &, histogram<false, S, A> &,
unsigned);
friend void serialize(Archive &, histogram<false, S, A> &, unsigned);
};
/// default static type factory

View File

@@ -64,8 +64,7 @@ public:
void increase(std::size_t i, value_type w) { container_[i] += w; }
value_type value(std::size_t i) const { return container_[i]; }
template <typename OtherStorage>
void operator+=(const OtherStorage &other) {
template <typename OtherStorage> void operator+=(const OtherStorage &other) {
for (std::size_t i = 0; i < container_.size(); ++i) {
container_[i] += other.value(i);
}