Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <type_traits>
- #include <array>
- namespace spy
- {
- template<int M, int N, int P> struct version
- {
- constexpr operator int() const { return P + 1000*(N + 1000*M); }
- };
- namespace detail
- {
- template<char... c> constexpr int find(int i0)
- {
- char arr[] = {c...};
- while(i0<sizeof...(c) && arr[i0] != '\'') { ++i0; }
- return i0;
- }
- template<char... c> constexpr int parse(int i0, int i1)
- {
- char arr[] = {c...};
- int value = 0;
- while(i0<i1 && arr[i0] != '\'')
- value = value*10 + (arr[i0++] - 48);
- return value;
- }
- }
- namespace literal
- {
- template<char ...c> constexpr auto operator"" _version()
- {
- using detail::parse;
- using detail::find;
- constexpr int e0 = find<c...>(0);
- constexpr int b1 = e0 + 1, e1 = find<c...>(b1);
- constexpr int b2 = e1+1 , e2 = sizeof...(c);
- return version<parse<c...>(0,e0)
- ,parse<c...>(b1,e1)
- ,parse<c...>(b2,e2)
- >{};
- }
- }
- }
- using namespace spy::literal;
- int x = 0'0'7_version;
Add Comment
Please, Sign In to add comment