is_thread_safe.hpp 985 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2021 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_ACCUMULATORS_IS_THREAD_SAFE_HPP
  7. #define BOOST_HISTOGRAM_ACCUMULATORS_IS_THREAD_SAFE_HPP
  8. #include <boost/histogram/detail/priority.hpp>
  9. #include <boost/histogram/fwd.hpp>
  10. #include <type_traits>
  11. namespace boost {
  12. namespace histogram {
  13. namespace detail {
  14. template <class T>
  15. constexpr bool is_thread_safe_impl(priority<0>) {
  16. return false;
  17. }
  18. template <class T>
  19. constexpr auto is_thread_safe_impl(priority<1>) -> decltype(T::thread_safe()) {
  20. return T::thread_safe();
  21. }
  22. } // namespace detail
  23. namespace accumulators {
  24. template <class T>
  25. struct is_thread_safe
  26. : std::integral_constant<bool,
  27. detail::is_thread_safe_impl<T>(detail::priority<1>{})> {};
  28. } // namespace accumulators
  29. } // namespace histogram
  30. } // namespace boost
  31. #endif