Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RHistUtils.hxx
Go to the documentation of this file.
1 /// \file ROOT/RHistData.h
2 /// \ingroup Hist ROOT7
3 /// \author Axel Naumann <axel@cern.ch>
4 /// \date 2016-06-01
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
6 
7 /*************************************************************************
8  * Copyright (C) 1995-2016, Rene Brun and Fons Rademakers. *
9  * All rights reserved. *
10  * *
11  * For the licensing terms see $ROOTSYS/LICENSE. *
12  * For the list of contributors see $ROOTSYS/README/CREDITS. *
13  *************************************************************************/
14 
15 #ifndef ROOT7_RHistUtils
16 #define ROOT7_RHistUtils
17 
18 #include <array>
19 #include <type_traits>
20 
21 namespace ROOT {
22 namespace Experimental {
23 namespace Hist {
24 
25 template <int DIMENSIONS>
26 struct RCoordArray: std::array<double, DIMENSIONS> {
27  using Base_t = std::array<double, DIMENSIONS>;
28 
29  /// Default construction.
30  RCoordArray() = default;
31 
32  /// Construction with one `double` per `DIMENSION`.
33  template<class...ELEMENTS, class = typename std::enable_if<sizeof...(ELEMENTS) + 1 == DIMENSIONS>::type>
34  RCoordArray(double x, ELEMENTS...el): Base_t{{x, el...}} {}
35 
36  /// Fallback constructor, invoked if the one above fails because of the wrong number of
37  /// arguments / coordinates.
38  template<class T, class...ELEMENTS, class = typename std::enable_if<sizeof...(ELEMENTS) + 1 != DIMENSIONS>::type>
39  RCoordArray(T, ELEMENTS...) {
40  static_assert(sizeof...(ELEMENTS) + 1 == DIMENSIONS, "Number of coordinates does not match DIMENSIONS");
41  }
42 
43  /// Construction from a C-style array.
44  RCoordArray(double (&arr)[DIMENSIONS]): Base_t(arr) {}
45 
46  /// Copy-construction from a C++-style array.
47  /// (No need for a move-constructor, it isn't any better for doubles)
48  RCoordArray(const std::array<double, DIMENSIONS>& arr): Base_t(arr) {}
49 };
50 
51 template <int DIMENSIONS>
52 //using CoordArray_t = std::array<double, DIMENSIONS>;
53 using CoordArray_t = RCoordArray<DIMENSIONS>;
54 
55 
56 } // namespace Hist
57 } // namespace Experimental
58 } // namespace ROOT
59 
60 #endif //ROOT7_THistUtils_h