fork download
  1. #include <utility>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. template <typename T>
  6. struct to_string;
  7.  
  8. template <char... cs>
  9. struct to_string<std::integer_sequence<char,cs...>>{
  10. std::string operator()() {
  11. return {cs...};
  12. }
  13. };
  14.  
  15. template <typename A, typename B>
  16. struct seq_cat;
  17.  
  18. template <char... A, char... B>
  19. struct seq_cat<std::integer_sequence<char,A...>,
  20. std::integer_sequence<char,B...>>
  21. {
  22. using result_t = std::integer_sequence<char, A..., B...>;
  23. };
  24.  
  25. constexpr char binary_to_char(char b7, char b6, char b5, char b4, char b3,
  26. char b2, char b1, char b0) {
  27. return (b7-'0') << 7 | (b6-'0') << 6
  28. | (b5-'0') << 5 | (b4-'0') << 4
  29. | (b3-'0') << 3 | (b2-'0') << 2
  30. | (b1-'0') << 1 | (b0-'0') << 0;
  31. }
  32.  
  33. template <char... cs>
  34. struct binary_to_ascii;
  35.  
  36. template <char b7, char b6, char b5, char b4, char b3, char b2, char b1, char b0>
  37. struct binary_to_ascii<b7,b6,b5,b4,b3,b2,b1,b0> {
  38. using result_t = std::integer_sequence
  39. < char,
  40. binary_to_char(b7,b6,b5,b4,b3,b2,b1,b0) >;
  41. };
  42.  
  43. template<char b7, char b6, char b5, char b4, char b3, char b2, char b1, char b0,
  44. char... rest>
  45. struct binary_to_ascii<b7,b6,b5,b4,b3,b2,b1,b0,rest...> {
  46. using result_t = typename seq_cat
  47. < std::integer_sequence< char, binary_to_char(b7,b6,b5,b4,b3,b2,b1,b0) >,
  48. typename binary_to_ascii<rest...>::result_t
  49. >::result_t;
  50. };
  51.  
  52. int main() {
  53. std::cout << to_string<binary_to_ascii<
  54. '0','1','1','0','0','0','0','1',
  55. '0','1','1','1','1','0','0','1',
  56. '0','1','1','1','1','0','0','1',
  57. '0','0','1','0','0','0','0','0',
  58. '0','1','1','0','1','1','0','0',
  59. '0','1','1','0','1','1','0','1',
  60. '0','1','1','0','0','0','0','1',
  61. '0','1','1','0','1','1','1','1'
  62. >::result_t>()() << "\n";
  63. }
Success #stdin #stdout 0s 3272KB
stdin
Standard input is empty
stdout
ayy lmao