make_default.hpp 742 B

123456789101112131415161718192021222324252627
  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_DETAIL_MAKE_DEFAULT_HPP
  7. #define BOOST_HISTOGRAM_DETAIL_MAKE_DEFAULT_HPP
  8. #include <boost/histogram/detail/detect.hpp>
  9. #include <boost/histogram/detail/static_if.hpp>
  10. namespace boost {
  11. namespace histogram {
  12. namespace detail {
  13. template <class T>
  14. auto make_default(const T& t) {
  15. return static_if<has_allocator<T>>([](const auto& t) { return T(t.get_allocator()); },
  16. [](const auto&) { return T{}; }, t);
  17. }
  18. } // namespace detail
  19. } // namespace histogram
  20. } // namespace boost
  21. #endif