• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
7 #ifndef BOOST_HISTOGRAM_LITERALS_HPP
8 #define BOOST_HISTOGRAM_LITERALS_HPP
9 
10 #include <type_traits>
11 
12 namespace boost {
13 namespace histogram {
14 namespace detail {
parse_number(unsigned n)15 constexpr unsigned parse_number(unsigned n) { return n; }
16 
17 template <class... Rest>
parse_number(unsigned n,char f,Rest...rest)18 constexpr unsigned parse_number(unsigned n, char f, Rest... rest) {
19   return parse_number(10u * n + static_cast<unsigned>(f - '0'), rest...);
20 }
21 } // namespace detail
22 
23 namespace literals {
24 /// Suffix operator to generate literal compile-time numbers, 0_c, 12_c, etc.
25 template <char... digits>
operator ""_c()26 auto operator"" _c() {
27   return std::integral_constant<unsigned, detail::parse_number(0, digits...)>();
28 }
29 } // namespace literals
30 } // namespace histogram
31 } // namespace boost
32 
33 #endif
34