1 #ifndef MENUPP_COMMON_HPP_
2 #define MENUPP_COMMON_HPP_
7 template<typename B
, typename
... Ts
>
8 using Extends
= typename
std::enable_if
<(... && std::is_base_of
<B
, Ts
>::value
)>::type
;
12 Into
, Up
, Down
, Left
, Right
15 template<typename T
= size_t, T Min
= 0, T Max
= 100>
18 static_assert(Min
<= Max
);
21 static constexpr Type min
= Min
;
22 static constexpr Type max
= Max
;
27 typename
R::Type Default
= 0,
28 typename
R::Type Inc
= 1,
33 static_assert(Inc
<= (R::max
- R::min
));
34 static_assert(Default
>= R::min
);
35 static_assert(Default
<= R::max
);
37 using Type
= typename
R::Type
;
39 static constexpr bool loop
= Loop
;
40 static constexpr Type inc
= Inc
;
41 static constexpr Type dflt
= Default
;
44 template<typename LevelConf
>
45 typename
LevelConf::Type
inc(typename
LevelConf::Type x
)
47 typename
LevelConf::Type ret
= x
+ LevelConf::inc
;
48 if constexpr(LevelConf::loop
) {
50 ret
= LevelConf::Range::min
;
51 else if (ret
> LevelConf::Range::max
)
52 ret
= LevelConf::Range::min
;
53 else if (ret
< LevelConf::Range::min
)
54 ret
= LevelConf::Range::max
;
57 ret
= LevelConf::Range::max
;
58 else if (ret
> LevelConf::Range::max
)
59 ret
= LevelConf::Range::max
;
60 else if (ret
< LevelConf::Range::min
)
61 ret
= LevelConf::Range::min
;
66 template<typename LevelConf
>
67 typename
LevelConf::Type
dec(typename
LevelConf::Type x
)
69 typename
LevelConf::Type ret
= x
- LevelConf::inc
;
70 if constexpr(LevelConf::loop
) {
72 ret
= LevelConf::Range::max
;
73 else if (ret
> LevelConf::Range::max
)
74 ret
= LevelConf::Range::min
;
75 else if (ret
< LevelConf::Range::min
)
76 ret
= LevelConf::Range::max
;
79 ret
= LevelConf::Range::min
;
80 else if (ret
> LevelConf::Range::max
)
81 ret
= LevelConf::Range::max
;
82 else if (ret
< LevelConf::Range::min
)
83 ret
= LevelConf::Range::min
;
90 #endif // MENUPP_COMMON_HPP_