1. Поиск говнокода

    Этот поиск практически ничего не может найти! Но вы всё-таки попытайтесь, вдруг повезет.

    Найдено: 35

  2. Си / Говнокод #27255

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    #include <stdio.h>
    #include <stdlib.h>
    #include <inttypes.h>
    
    int main(void)
    {
      uint32_t uint32max = UINT32_MAX;
      int32_t int32_minus_one = -1;
      printf("uint32_max = %" PRIu32 "\n", uint32max);
      printf("int32_minus_one = %" PRIi32 "\n", int32_minus_one);
      if (uint32max > int32_minus_one)
      {
        puts("uint32max > int32_minus_one");
      }
      else if (uint32max < int32_minus_one)
      {
        puts("uint32max < int32_minus_one");
      }
      else
      {
        puts("uint32max == int32_minus_one");
      }
      return EXIT_SUCCESS;
    }

    Почему в Си нет особого правила при сравнении signed и unsigned типов, ну типа если значение в signed типе отрицательно, то он полюбасу будет меньше любого unsigned значения? А то говно какое-то.

    (нет, я понимаю почему так происходит, но все равно говно)

    j123123, 15 Февраля 2021

    Комментарии (31)
  3. C++ / Говнокод #26983

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    #include <cstdlib>
    #include <chrono>
    #include <iostream>
    #include <thread>
    
    int p = 0;
    int *q = nullptr;
    
    void g()
    {
        using namespace std::chrono_literals;
    
        std::cout << "g()" << std::endl;
    
        std::cout << "g(): p = 1" << std::endl;
        p = 1;
    
        std::this_thread::sleep_for(1s);
    
        
        if (q != nullptr) {
            std::cout << "g(): *q = 1" << std::endl;
            *q = 1;
        } else {
            std::cout << "g(): q == nullptr" << std::endl;
        }
    }
    
    void f()
    {
        using namespace std::chrono_literals;
    
        std::cout << "f()" << std::endl;
    
        if (p == 0) {
            std::cout << "f(): first loop start" << std::endl;
            while (p == 0) { }  // Потенциально конечный
            std::cout << "f(): first loop end" << std::endl;
        }
    
        int i = 0;
        q = &i;
        std::cout << "f(): second loop start" << std::endl;
        while (i == 0) { }  // Потенциально конечный, хотя в условии только автоматическая пельменная
        std::cout << "f(): second loop end" << std::endl;
    }
    
    int main()
    {
        using namespace std::chrono_literals;
    
        std::cout << "f() thread start" << std::endl;
        auto thr1 = std::thread(f);
        thr1.detach();
        std::this_thread::sleep_for(1s);
    
        std::cout << "g() thread start" << std::endl;
        auto thr2 = std::thread(g);
        thr2.detach();
        std::this_thread::sleep_for(2s);
    
        std::cout << "Done" << std::endl;
        
        std::_Exit(EXIT_SUCCESS);
    }

    Ожидание:

    f() thread start
    f()
    f(): first loop start
    g() thread start
    g()
    g(): p = 1
    f(): first loop end
    f(): second loop start
    g(): *q = 1
    f(): second loop end
    Done

    gost, 28 Сентября 2020

    Комментарии (75)
  4. Си / Говнокод #26982

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    /* https://habr.com/ru/company/piter/blog/491996/
    
    Пусть в Python такая штука и называется генератором, в языке C++ она
    называлась бы корутиной. Пример взят с этого сайта: https://masnun.com/2015/11/13/python-generators-coroutines-native-coroutines-and-async-await.html
    
    def generate_nums():
         num = 0
         while True:
              yield num
              num = num + 1	
    
    nums = generate_nums()
    	
    for x in nums:
         print(x)
    	
         if x > 9:
    */
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <stdint.h>
    #include <stdbool.h>
    
    #define START 0
    #define YIELD 1
    
    typedef struct 
    {
      uint8_t jmpto;
      int num;
    } coroutine_state;
    
    
    int generate_nums(coroutine_state *state)
    {
      switch(state->jmpto)
      {
        case START: break;
        case YIELD: goto yield;
      }
      while (true)
      {
        state->jmpto = YIELD; return state->num; yield: // какая питушня
    
        state->num = state->num + 1;
      }
    }
    
    
    
    
    int main(void)
    {
      int x;
      coroutine_state st = {START, 0};
      while(true)
      {
        x = generate_nums(&st);
        printf("%d\n", x);
    
        if (x > 9)
        {
          break;
        }
      }
      return EXIT_SUCCESS;
    }

    Попробовал переписать эту ко-ко-корутину c питуха на Си - получилась какая-то херня нечитаемая. что еще раз доказывает, что корутины нахуй не нужны

    К тому же в крестопарашном говне они требуют хип, а это нахуй не нужно на самом-то деле.

    j123123, 28 Сентября 2020

    Комментарии (17)
  5. C++ / Говнокод #26913

    +3

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    int main()
    {   
        using output1 = Eval<
            Input<'H', 'e', 'l', 'l', 'o'>,
            App<
                ',', '>', ',', '>', ',', '>', ',', '>', ',', '>',
                '<', '.', '<', '.', '<', '.', '<', '.', '<', '.'
            >
        >;
        std::cout << "Hello reverse (read/write): " << SpanToStringContinuous<output1>::value() << std::endl;
    
        using output2 = Eval<
            Input<>,
            App<'+', '+', '+', '[', '-', ']'>
        >;
        std::cout << "Simple loop (empty output): " << SpanToStringContinuous<output2>::value() << std::endl;
    
        // Source: Wikipedia
        using output3 = Eval<
            Input<>,
            App<
                '+', '+', '+', '+', '+', '+', '+', '+', '[', '>', '+', '+', '+',
                '+', '[', '>', '+', '+', '>', '+', '+', '+', '>', '+', '+', '+',
                '>', '+', '<', '<', '<', '<', '-', ']', '>', '+', '>', '+', '>',
                '-', '>', '>', '+', '[', '<', ']', '<', '-', ']', '>', '>', '.',
                '>', '-', '-', '-', '.', '+', '+', '+', '+', '+', '+', '+', '.',
                '.', '+', '+', '+', '.', '>', '>', '.', '<', '-', '.', '<', '.',
                '+', '+', '+', '.', '-', '-', '-', '-', '-', '-', '.', '-', '-',
                '-', '-', '-', '-', '-', '-', '.', '>', '>', '+', '.', '>', '+',
                '+', '.'
            >
        >;
        std::cout << "Hello World (wiki): " << SpanToStringContinuous<output3>::value() << std::endl;
    
    
        return EXIT_SUCCESS;
    }

    https://wandbox.org/permlink/AERueBhsiS4WxGZY, https://pastebin.com/Cywe05JY

    Напейсал полностью компайл-таймовый интерпретатор «Брейнфака» на крестовых шаблонах.

    gost, 03 Сентября 2020

    Комментарии (104)
  6. Си / Говнокод #26864

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    #include <stdio.h>
    #include <stdlib.h>
    
    #define SPLICE(a,b) SPLICE_1(a,b)
    #define SPLICE_1(a,b) SPLICE_2(a,b)
    #define SPLICE_2(a,b) a##b
     
     
    #define PP_ARG_N( \
              _1,  _2,  _3,  _4,  _5,  _6,  _7,  _8,  _9, _10, \
             _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
             _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
             _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
             _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
             _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \
             _61, _62, _63, N, ...) N
     
    /* Note 63 is removed */
    #define PP_RSEQ_N()                                        \
             62, 61, 60,                                       \
             59, 58, 57, 56, 55, 54, 53, 52, 51, 50,           \
             49, 48, 47, 46, 45, 44, 43, 42, 41, 40,           \
             39, 38, 37, 36, 35, 34, 33, 32, 31, 30,           \
             29, 28, 27, 26, 25, 24, 23, 22, 21, 20,           \
             19, 18, 17, 16, 15, 14, 13, 12, 11, 10,           \
              9,  8,  7,  6,  5,  4,  3,  2,  1,  0
     
    #define PP_NARG_(...)    PP_ARG_N(__VA_ARGS__)    
     
    /* Note dummy first argument _ and ##__VA_ARGS__ instead of __VA_ARGS__ */
    #define PP_NARG(...)     PP_NARG_(_, ##__VA_ARGS__, PP_RSEQ_N())
    
    
    #define PRINT_1(a1) \
      printf(a1);
     
    #define PRINT_2(a1, b1) \
      printf(a1, b1);
     
    #define PRINT_3(a1, b1, a2) \
      PRINT_2(a1, b1); PRINT_1(a2)
     
    #define PRINT_4(a1, b1, a2, b2) \
      PRINT_2(a1, b1); PRINT_2(a2, b2);
     
    #define PRINT_5(a1, b1, a2, b2, a3) \
      PRINT_4(a1, b1, a2, b2); PRINT_1(a3);
     
    #define PRINT_6(a1, b1, a2, b2, a3, b3) \
      PRINT_4(a1, b1, a2, b2); PRINT_2(a3, b3)
     
    #define PRINT_7(a1, b1, a2, b2, a3, b3, a4) \
      PRINT_6(a1, b1, a2, b2, a3, b3); PRINT_1(a4)
     
    #define PRINT_8(a1, b1, a2, b2, a3, b3, a4, b4) \
      PRINT_6(a1, b1, a2, b2, a3, b3);  PRINT_2(a4, b4);
    //..... дальше лень ...
     
    #define PRINTS_(N, ...) \
      SPLICE(PRINT_, N)(__VA_ARGS__)
     
    #define PRINTS(...) \
      PRINTS_(PP_NARG(__VA_ARGS__), __VA_ARGS__)
    
    
    int main(void)
    {
        PRINTS("10 = %d", 10, "; 3 + 3 = %d", 3+3, "\n" );
        return EXIT_SUCCESS;
    }

    Имитация крестопарашного cout через препроцессор
    https://wandbox.org/permlink/px4DCDSCGfUlbcFL

    j123123, 14 Августа 2020

    Комментарии (8)
  7. C++ / Говнокод #26703

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    // https://godbolt.org/z/QAR_nT
    // https://govnokod.ru/26701#comment550329
    #include <cstddef>
    #include <string>
    #include <cassert>
    
    
    struct assert_failure
    {
        explicit assert_failure(const char *sz)
        {
            std::fprintf(stderr, "Assertion failure: %s\n", sz);
            std::quick_exit(EXIT_FAILURE);
        }
    };
    
    // эта херня не совсем корректно будет обрабатывать всякую хрень вроде ", , , " - оно это посчитает за 4 аргумента,
    // и если считать " скобочки, тогда еще надо запилить обработку эскейп-последовательности, для хуйни типа "pidor\" govno"
    // но мне лень эту хуйню допиливать.
    constexpr std::size_t count_args(const char *s, std::size_t depth = 0, std::size_t pos = 0, std::size_t count = 0)
    {
      if (s[pos] == '\0'){
        if(depth != 0)
          throw assert_failure("kakoi bagor)))\n");
        if(pos == 0)
          return 0;
        return count+1;
      }
      else if(s[pos] == '{')
      {
        return count_args(s, depth + 1, pos + 1, count);
      }
      else if(s[pos] == '}')
      {
        if(depth == 0)
          throw assert_failure("kakoi bagor)))\n");
        return count_args(s, depth - 1, pos + 1, count);
      }
      else if(depth == 0)
      {
        if(s[pos] == ',')
        {
          return count_args(s, depth, pos + 1,  count + 1);
        }
      }
      return count_args(s, depth, pos+1,  count); 
    }
    
    #define TO_STR(...) #__VA_ARGS__
    #define ARGNUM(...) count_args(TO_STR(__VA_ARGS__))
    
    #define krestogovnotypeof(a) std::remove_reference<a>::type
    
    #define FOR_RANGE(type, varname, ...) for(struct {size_t cnt; krestogovnotypeof(type) arr[ ARGNUM(__VA_ARGS__)  ];  } varname = {0, {__VA_ARGS__}}; varname.cnt < sizeof(varname.arr)/sizeof(type); ++varname.cnt )
    
    int main(void)
    {
      FOR_RANGE(int[2], k, {1,2}, {3,4}, {5,6}, {7,8})
        printf("{%d %d},\n", k.arr[k.cnt][0], k.arr[k.cnt][1]);
      return EXIT_SUCCESS;
    }

    Какая крестопараша((( В вижуальхуюдии вроде собирается, но проверить корректность работы не могу. Как вы этим днищекомпилятором вообще пользуетесь?

    Было б круто, если бы были такие constexpr функции, которые в компилтайме могут куски исходного кода высирать как бы прямо в исходник, и потом уже чтоб это компилировалось

    j123123, 29 Мая 2020

    Комментарии (232)
  8. Си / Говнокод #26643

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    #include <stdio.h>
    #include <stdlib.h>
    
    typedef struct {
      int field1;
      int field2;
    } teststr;
    
    typedef struct {
      char data[sizeof(teststr)];
    } teststr_holder __attribute__ (( aligned (__alignof__ (teststr)) ));
    
    typedef union {
      teststr n1;
      teststr_holder n2;
    } str_conv;
    
    int field1_get(teststr_holder a)
    {
      str_conv cnv = {.n2 = a};
      return cnv.n1.field1;
    }
    
    int field2_get(teststr_holder a)
    {
      str_conv cnv = {.n2 = a};
      return cnv.n1.field2;
    }
    
    teststr_holder init_teststr(int field1, int field2)
    {
      str_conv cnv = {.n1 = {field1, field2}};
      return cnv.n2;
    }
    
    int main(void)
    {
      teststr_holder a = init_teststr(1234, 5678);
      printf("%d %d\n", field1_get(a), field2_get(a));
      return EXIT_SUCCESS;
    }

    Какое сокрытие )))

    j123123, 09 Мая 2020

    Комментарии (64)
  9. C++ / Говнокод #26621

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    struct Base { virtual const char *getName() = 0; virtual ~Base() = default; };
    struct SE_0 : Base { virtual const char *getName() override { return "SE_0"; } };
    struct SE_1 : Base { virtual const char *getName() override { return "SE_1"; } };
    struct SE_2 : Base { virtual const char *getName() override { return "SE_2"; } };
    
    enum TypesEnum {
        E__BEGIN = 0,
    
        E_0 = E__BEGIN,
        E_1,
        E_2,
    
        E__END
    };
    
    template<TypesEnum>
    struct Registry {};
    
    template<>
    struct Registry<E_0> {
        static constexpr const char *name = "The first type (SE_0)";
        using type = SE_0;
    };
    
    template<>
    struct Registry<E_1> {
        static constexpr const char *name = "A second type (SE_1)";
        using type = SE_1;
    };
    
    template<>
    struct Registry<E_2> {
        static constexpr const char *name = "And the last type (SE_2)";
        using type = SE_2;
    };
    
    template<TypesEnum CurrentType>
    std::unique_ptr<Base> createTypeImpl(const char *name)
    {
        if constexpr (CurrentType < E__END) {
            if (strstr(Registry<CurrentType>::name, name)) {
                return std::make_unique<typename Registry<CurrentType>::type>();
            }
            return createTypeImpl<static_cast<TypesEnum>(CurrentType + 1)>(name);
        } else {
            (void)name;  // Silence 'unreferenced formal parameter' warning
            return nullptr;
        }
    }
    
    std::unique_ptr<Base> createType(const char *name)
    {
        return createTypeImpl<E__BEGIN>(name);
    }
    
    int main()
    {
        std::cout << "first type: " << createType("first type")->getName() << std::endl;
        std::cout << "second type: " << createType("second type")->getName() << std::endl;
        std::cout << "last type: " << createType("last type")->getName() << std::endl;
    
        return EXIT_SUCCESS;
    }

    Упоролся.
    https://ideone.com/c11fz4

    gost, 29 Апреля 2020

    Комментарии (109)
  10. Си / Говнокод #26430

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    // https://www.linux.org.ru/forum/development/15520475
    // *Какой #define макрит for в while?
    
    #include <stdio.h>
    #include <stdlib.h>
    
    #define FOR(a, b, c, ...) {a;while(b){__VA_ARGS__ c;}}
    
    int main(void)
    {
      for(int i = 0; i < 10; i++)
      {
        printf("test %d\n", i);
      }
      
      printf("\n");
      
      FOR(int i = 0, i < 10, i++,
      {
        printf("test %d\n", i);
      }   
      )
        
      return EXIT_SUCCESS;
    }

    j123123, 10 Февраля 2020

    Комментарии (3)
  11. C++ / Говнокод #26308

    +4

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    int main()
    {
        using ToString::ExprToString;
    
        using Result1 = Eval<Expr<Add,
            Expr<Div, Int<5>, Int<3>>,
            Expr<Div, Int<6>, Int<8>>>>;
        std::cout << ExprToString<Result1>::toString() << std::endl;  // 5/3 + 6/8 = (29 / 12)
    
        using Result2 = Eval<Expr<Div, Int<100>, Int<20>>>;
        std::cout << ExprToString<Result2>::toString() << std::endl;  // 5
    
        using Result3 = Eval<Expr<Div, Int<27>, Int<24>>>;
        std::cout << ExprToString<Result3>::toString() << std::endl;  // (9 / 8)
    
        using Result4 = Eval<Expr<Mul,
            Expr<Div, Int<5>, Int<3>>,
            Expr<Div, Int<6>, Int<8>>>>;
        std::cout << ExprToString<Result4>::toString() << std::endl;  // 5/3 * 6/8 = (5 / 4)
    
        using Result5 = Eval<Expr<Derivative, Var<0>, Expr<Mul, Var<0>, Var<0>>>>;
        std::cout << ExprToString<Result5>::toString() << std::endl;  // d/dx x*x = 2*x = (Var(0) * 2)
    
        using Result6 = Eval<Expr<Derivative, Var<0>, Expr<Div, Int<2>, Var<0>>>>;
        std::cout << ExprToString<Result6>::toString() << std::endl;  // d/dx 2/x = -2 * x^2
    
        return EXIT_SUCCESS;
    }

    Написал калькулятор с символьными вычислениями на шаблонах. Получился «Лисп».
    https://wandbox.org/permlink/vAHC5IpyIIyQhUjJ

    gost, 04 Января 2020

    Комментарии (16)