fwd.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // Copyright 2015-2019 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. #ifndef BOOST_HISTOGRAM_FWD_HPP
  7. #define BOOST_HISTOGRAM_FWD_HPP
  8. /**
  9. \file boost/histogram/fwd.hpp
  10. Forward declarations, tag types and type aliases.
  11. */
  12. #include <boost/config.hpp> // BOOST_ATTRIBUTE_NODISCARD
  13. #include <boost/core/use_default.hpp>
  14. #include <tuple>
  15. #include <type_traits>
  16. #include <vector>
  17. namespace boost {
  18. namespace histogram {
  19. /// Tag type to indicate use of a default type
  20. using boost::use_default;
  21. namespace axis {
  22. /// Integral type for axis indices
  23. using index_type = int;
  24. /// Real type for axis indices
  25. using real_index_type = double;
  26. /// Empty metadata type
  27. struct null_type {
  28. template <class Archive>
  29. void serialize(Archive&, unsigned /* version */) {}
  30. };
  31. /// Another alias for an empty metadata type
  32. using empty_type = null_type;
  33. // some forward declarations must be hidden from doxygen to fix the reference docu :(
  34. #ifndef BOOST_HISTOGRAM_DOXYGEN_INVOKED
  35. namespace transform {
  36. struct id;
  37. struct log;
  38. struct sqrt;
  39. struct pow;
  40. } // namespace transform
  41. template <class Value = double, class Transform = use_default,
  42. class MetaData = use_default, class Options = use_default>
  43. class regular;
  44. template <class Value = int, class MetaData = use_default, class Options = use_default>
  45. class integer;
  46. template <class Value = double, class MetaData = use_default, class Options = use_default,
  47. class Allocator = std::allocator<Value>>
  48. class variable;
  49. template <class Value = int, class MetaData = use_default, class Options = use_default,
  50. class Allocator = std::allocator<Value>>
  51. class category;
  52. template <class MetaData = use_default>
  53. class boolean;
  54. template <class... Ts>
  55. class variant;
  56. #endif // BOOST_HISTOGRAM_DOXYGEN_INVOKED
  57. } // namespace axis
  58. #ifndef BOOST_HISTOGRAM_DOXYGEN_INVOKED
  59. template <class T>
  60. struct weight_type;
  61. template <class T>
  62. struct sample_type;
  63. namespace accumulators {
  64. template <class ValueType = double>
  65. class count;
  66. template <class ValueType = double>
  67. class sum;
  68. template <class ValueType = double>
  69. class weighted_sum;
  70. template <class ValueType = double>
  71. class mean;
  72. template <class ValueType = double>
  73. class weighted_mean;
  74. template <class T>
  75. class thread_safe;
  76. template <class T>
  77. struct is_thread_safe : std::false_type {};
  78. template <class T>
  79. struct is_thread_safe<thread_safe<T>> : std::true_type {};
  80. } // namespace accumulators
  81. struct unsafe_access;
  82. template <class Allocator = std::allocator<char>>
  83. class unlimited_storage;
  84. template <class T>
  85. class storage_adaptor;
  86. #endif // BOOST_HISTOGRAM_DOXYGEN_INVOKED
  87. /// Vector-like storage for fast zero-overhead access to cells.
  88. template <class T, class A = std::allocator<T>>
  89. using dense_storage = storage_adaptor<std::vector<T, A>>;
  90. /// Default storage, optimized for unweighted histograms
  91. using default_storage = unlimited_storage<>;
  92. /// Dense storage which tracks sums of weights and a variance estimate.
  93. using weight_storage = dense_storage<accumulators::weighted_sum<>>;
  94. /// Dense storage which tracks means of samples in each cell.
  95. using profile_storage = dense_storage<accumulators::mean<>>;
  96. /// Dense storage which tracks means of weighted samples in each cell.
  97. using weighted_profile_storage = dense_storage<accumulators::weighted_mean<>>;
  98. // some forward declarations must be hidden from doxygen to fix the reference docu :(
  99. #ifndef BOOST_HISTOGRAM_DOXYGEN_INVOKED
  100. template <class Axes, class Storage = default_storage>
  101. class BOOST_ATTRIBUTE_NODISCARD histogram;
  102. #endif // BOOST_HISTOGRAM_DOXYGEN_INVOKED
  103. namespace detail {
  104. /* Most of the histogram code is generic and works for any number of axes. Buffers with a
  105. * fixed maximum capacity are used in some places, which have a size equal to the rank of
  106. * a histogram. The buffers are statically allocated to improve performance, which means
  107. * that they need a preset maximum capacity. 32 seems like a safe upper limit for the rank
  108. * (you can nevertheless increase it here if necessary): the simplest non-trivial axis has
  109. * 2 bins; even if counters are used which need only a byte of storage per bin, 32 axes
  110. * would generate of 4 GB.
  111. */
  112. #ifndef BOOST_HISTOGRAM_DETAIL_AXES_LIMIT
  113. #define BOOST_HISTOGRAM_DETAIL_AXES_LIMIT 32
  114. #endif
  115. template <class T>
  116. struct buffer_size_impl
  117. : std::integral_constant<std::size_t, BOOST_HISTOGRAM_DETAIL_AXES_LIMIT> {};
  118. template <class... Ts>
  119. struct buffer_size_impl<std::tuple<Ts...>>
  120. : std::integral_constant<std::size_t, sizeof...(Ts)> {};
  121. template <class T>
  122. using buffer_size = typename buffer_size_impl<T>::type;
  123. } // namespace detail
  124. } // namespace histogram
  125. } // namespace boost
  126. #endif