Advertisement
horvathm

Day 18, part 2, C++ metaprogramming

Dec 18th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 26.42 KB | None | 0 0
  1. #include <cstdint>
  2. #include <type_traits>
  3.  
  4. struct N {
  5.     int64_t v;
  6. };
  7.  
  8. constexpr N operator "" _(unsigned long long v) { return { int64_t(v) }; }
  9. constexpr N operator/(N a, N b) { return { a.v + b.v }; }
  10. constexpr N operator-(N a, N b) { return { a.v * b.v }; }
  11.  
  12. template<int64_t V> struct Result {
  13.     static_assert(!V);
  14. };
  15.  
  16. // Process your input like this:
  17. // sed -E 's/([0-9]+)/\1_/g ; s/\*/-/g ; s/\+/\//g ; s/^/(/g ; s/$/) \//' input
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement