1#ifndef __DUNE_ACFEM_COMMON_LITERALS_HH__
2#define __DUNE_ACFEM_COMMON_LITERALS_HH__
5#include "../mpl/accumulate.hh"
6#include "../mpl/sequenceslice.hh"
7#include "../mpl/compare.hh"
8#include "fractionconstant.hh"
23 template<
class Seq,
class SFINAE =
void>
24 struct IntParserHelper;
30 template<
char c0,
char... c>
31 struct IntParserHelper<
Sequence<char, c0, c...>,
32 std::enable_if_t<c0 != '0' || sizeof...(c) == 0> >
35 static constexpr std::size_t base = 10;
37 "Expecting a sequence of non-negative decimal digits");
41 template<
char c2,
char... c>
42 struct IntParserHelper<
Sequence<char, '0', c2, c...>,
std::enable_if_t<c2 == 'x' || c2 == 'X'> >
46 : ((c >=
'a' && c <=
'f')
48 : ((c >=
'A' && c <=
'F')
51 static constexpr std::size_t base = 16;
53 "Expecting a sequence of non-negative binary digits");
57 template<
char c2,
char... c>
58 struct IntParserHelper<
Sequence<char, '0', c2, c...>,
std::enable_if_t<c2 == 'b' || c2 == 'B'> >
61 static constexpr std::size_t base = 2;
63 "Expecting a sequence of non-negative binary digits");
67 template<
char c2,
char... c>
68 struct IntParserHelper<
70 std::enable_if_t<c2 != 'x' && c2 != 'X' && c2 != 'b' && c2 != 'B'>
74 static constexpr std::size_t base = 8;
76 "Expecting a sequence of non-negative octal digits");
82 constexpr auto integerLiteral()
84 using Traits = IntParserHelper<
Sequence<char, c...> >;
85 using Digits =
typename Traits::Digits;
86 constexpr std::size_t base = Traits::base;
87 return AccumulateSequence<MultiplyAddFunctor<std::size_t, base>, ReverseSequence<Digits> >{};
93 constexpr auto operator"" _c ()
95 return integerLiteral<c...>();
102 constexpr auto operator"" _f ()
104 return TypedValue::intFraction(integerLiteral<c...>());
MakeIndexSequence< N, Value, 0 > MakeConstantSequence
Generate a constant index sequence of the given size.
Definition: generators.hh:45
Sequence< std::size_t, V... > IndexSequence
Sequence of std::size_t values.
Definition: types.hh:64
std::integer_sequence< T, V... > Sequence
Sequence of any type of integer values.
Definition: types.hh:56