literals.hpp 916 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2015-2017 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_LITERALS_HPP
  7. #define BOOST_HISTOGRAM_LITERALS_HPP
  8. #include <type_traits>
  9. namespace boost {
  10. namespace histogram {
  11. namespace detail {
  12. constexpr unsigned parse_number(unsigned n) { return n; }
  13. template <class... Rest>
  14. constexpr unsigned parse_number(unsigned n, char f, Rest... rest) {
  15. return parse_number(10u * n + static_cast<unsigned>(f - '0'), rest...);
  16. }
  17. } // namespace detail
  18. namespace literals {
  19. /// Suffix operator to generate literal compile-time numbers, 0_c, 12_c, etc.
  20. template <char... digits>
  21. auto operator"" _c() {
  22. return std::integral_constant<unsigned, detail::parse_number(0, digits...)>();
  23. }
  24. } // namespace literals
  25. } // namespace histogram
  26. } // namespace boost
  27. #endif