1. C++ / Говнокод #14213

    +6

    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
    class Log
    {
    
    	ReverseStruct<std::list<std::string> > _logList;
    	semafor semafor;
    	Log()
    	{
    		std::list<std::string> right , left;
    		std::shared_ptr<std::list<std::string> > ptrRight=std::shared_ptr<std::list<std::string> >(*right);
    		std::shared_ptr<std::list<std::string> > ptrLeft=std::shared_ptr<std::list<std::string> >(*left);
    		_logList=TReverseStruct<std::list<std::string> >(ptrRight,ptrLeft);
    	}
    
    
    	void writeMessage(std::string message, Level level ){_logList.getWriteStorage.push_back( currentTime+level+messge); semafor.signal();}
    	void body()
    	{
    		try
    		{
    			semafor.wait();
    			_logList.revers();
    			for (std::list<std::string>::iterator i =_logList.getReadStorage->begin(); i != _logList.getReadStorage->end(); ++i)
    			{
    			fixedBufferString<7000, '\0'> stringLog;
    			stringLog.append(*i);
    			FileDevice flashInternal(FLASHINTERNAL);
    			const DriveErrors::E WriteResult = flashInternal.writeFile("log.iso", (byte*)stringLog.content(), stringLog.length());
    			}
    		}
    		catch()
    		{}
    	}
    }

    laMer007, 11 Декабря 2013

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

    +15

    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
    if( (Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 165 && Input.GetMouseY() <= 197) || (Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 205 && Input.GetMouseY() <= 237) ||
                (Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 85 && Input.GetMouseY() <= 117) || (Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 125 && Input.GetMouseY() <= 157) ||
    
               (Input.GetMouseX() >= 675 && Input.GetMouseX() <= 707 && Input.GetMouseY() >= 85 && Input.GetMouseY() <= 117) || (Input.GetMouseX() >= 675 && Input.GetMouseX() <= 707 && Input.GetMouseY() >= 145 && Input.GetMouseY() <= 177) ||
               (Input.GetMouseX() >= 675 && Input.GetMouseX() <= 707 && Input.GetMouseY() >= 205 && Input.GetMouseY() <= 237)||
    
               (Input.GetMouseX() >= 780 && Input.GetMouseX() <= 807 && Input.GetMouseY() >= 85 && Input.GetMouseY() <= 117) || (Input.GetMouseX() >= 780 && Input.GetMouseX() <= 807 && Input.GetMouseY() >= 125 && Input.GetMouseY() <= 157) ||
               (Input.GetMouseX() >= 780 && Input.GetMouseX() <= 807 && Input.GetMouseY() >= 165 && Input.GetMouseY() <= 197) || (Input.GetMouseX() >= 780 && Input.GetMouseX() <= 807 && Input.GetMouseY() >= 205 && Input.GetMouseY() <= 237) ||
    
               ...
    
            {
                int i; int e;
                if(Input.GetMouseX() >= 55 && Input.GetMouseX() <= 87 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 0;
                if(Input.GetMouseX() >= 95 && Input.GetMouseX() <= 127 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 1;
                if(Input.GetMouseX() >= 135 && Input.GetMouseX() <= 167 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 2;
                if(Input.GetMouseX() >= 175 && Input.GetMouseX() <= 207 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 3;
                if(Input.GetMouseX() >= 215 && Input.GetMouseX() <= 247 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 4;
                if(Input.GetMouseX() >= 255 && Input.GetMouseX() <= 287 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 5;
                if(Input.GetMouseX() >= 295 && Input.GetMouseX() <= 327 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 6;
                if(Input.GetMouseX() >= 335 && Input.GetMouseX() <= 367 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 7;
    
                if(Input.GetMouseX() >= 55 && Input.GetMouseX() <= 87 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 8;
                if(Input.GetMouseX() >= 95 && Input.GetMouseX() <= 127 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 9;
                if(Input.GetMouseX() >= 135 && Input.GetMouseX() <= 167 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 10;
                if(Input.GetMouseX() >= 175 && Input.GetMouseX() <= 207 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 11;
                if(Input.GetMouseX() >= 215 && Input.GetMouseX() <= 247 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 12;
                if(Input.GetMouseX() >= 255 && Input.GetMouseX() <= 287 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 13;
                if(Input.GetMouseX() >= 295 && Input.GetMouseX() <= 327 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 14;
                if(Input.GetMouseX() >= 335 && Input.GetMouseX() <= 367 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 15;
    
                ...
    
                if(Input.GetMouseX() >= 55 && Input.GetMouseX() <= 87 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 40;
                if(Input.GetMouseX() >= 95 && Input.GetMouseX() <= 127 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 41;
                if(Input.GetMouseX() >= 135 && Input.GetMouseX() <= 167 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 42;
                if(Input.GetMouseX() >= 175 && Input.GetMouseX() <= 207 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 43;
                if(Input.GetMouseX() >= 215 && Input.GetMouseX() <= 247 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 44;
                if(Input.GetMouseX() >= 255 && Input.GetMouseX() <= 287 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 45;
                if(Input.GetMouseX() >= 295 && Input.GetMouseX() <= 327 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 46;
                if(Input.GetMouseX() >= 335 && Input.GetMouseX() <= 367 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 47;
    
               if(Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 85 && Input.GetMouseY() <= 117) e = 0; // Bracers
               if(Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 125 && Input.GetMouseY() <= 157) e = 1; // Hands
               if(Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 165 && Input.GetMouseY() <= 197) e = 2; // Sword
               if(Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 205 && Input.GetMouseY() <= 237) e = 3; // Off hand
    
               if(Input.GetMouseX() >= 675 && Input.GetMouseX() <= 707 && Input.GetMouseY() >= 85 && Input.GetMouseY() <= 117) e = 4; // Helmet
               if(Input.GetMouseX() >= 675 && Input.GetMouseX() <= 707 && Input.GetMouseY() >= 145 && Input.GetMouseY() <= 177) e = 5; // Chest
               if(Input.GetMouseX() >= 675 && Input.GetMouseX() <= 707 && Input.GetMouseY() >= 205 && Input.GetMouseY() <= 237)  e = 6; // Legs

    https://github.com/LaurentGomila/SFML/wiki/Tutorial%3A-Basic-Inventory-System

    Crazy_penguin, 11 Декабря 2013

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

    +9

    1. 1
    #   define BOOST_MPL_AUX_NTTP_DECL(T, x) T x

    Очень интересный стайлгайд Алексей Гуртового

    crastinus, 07 Декабря 2013

    Комментарии (25)
  4. C++ / Говнокод #14194

    +9

    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
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    int numBlock = 0;
        for(int i = 0; i < 16; i++)
            for(int j = 0; j < 25; j++)
            {
    
            if(levelInfo[i][j].active)
            {
            if(levelInfo[i][j].part && levelInfo[i][j].type) continue;
            if(levelInfo[i][j].type)
            {
                tempLevel[numBlock*8  ] = i*24;
                tempLevel[numBlock*8+1] = (j)*24;
                tempLevel[numBlock*8+2] = (i+2)*24;
                tempLevel[numBlock*8+3] = (j)*24;
                tempLevel[numBlock*8+4] = (i+2)*24;
                tempLevel[numBlock*8+5] = (j+1)*24;
                tempLevel[numBlock*8+6] = i*24;
                tempLevel[numBlock*8+7] = (j+1)*24;
            }
            else
            {
                tempLevel[numBlock*8  ] = i*24;
                tempLevel[numBlock*8+1] = (j)*24;
                tempLevel[numBlock*8+2] = (i+1)*24;
                tempLevel[numBlock*8+3] = (j)*24;
                tempLevel[numBlock*8+4] = (i+1)*24;
                tempLevel[numBlock*8+5] = (j+1)*24;
                tempLevel[numBlock*8+6] = i*24;
                tempLevel[numBlock*8+7] = (j+1)*24;
            }
    
            if(levelInfo[i][j].type)
                for(int k = 0; k < 8; k++) tempTex[numBlock*8+k] = coord[0][k];
            else
                for(int k = 0; k < 8; k++) tempTex[numBlock*8+k] = coord[1][k];
            }
            else
            {
            tempLevel[numBlock*8  ] = i*24;
            tempLevel[numBlock*8+1] = (j)*24;
            tempLevel[numBlock*8+2] = (i+1)*24;
            tempLevel[numBlock*8+3] = (j)*24;
            tempLevel[numBlock*8+4] = (i+1)*24;
            tempLevel[numBlock*8+5] = (j+1)*24;
            tempLevel[numBlock*8+6] = i*24;
            tempLevel[numBlock*8+7] = (j+1)*24;
            for(int k = 0; k < 8; k++) tempTex[numBlock*8+k] = coord[2][k];
            }
            numBlock++;
            }
    
        for(int i = 0; i < 2; i++)
            for(int j = 0; j < 3; j++)
            {
                if(!fallBlocks[i][j].active) continue;
                if(fallBlocks[i][j].part && fallBlocks[i][j].type) continue;
                if(!fallBlocks[i][j].type)
                {
                    tempLevel[numBlock*8  ] = (fallPosX+i)*24;
                    tempLevel[numBlock*8+1] = (fallPosY-j)*24;
                    tempLevel[numBlock*8+2] = (fallPosX+i+1)*24;
                    tempLevel[numBlock*8+3] = (fallPosY-j)*24;
                    tempLevel[numBlock*8+4] = (fallPosX+i+1)*24;
                    tempLevel[numBlock*8+5] = (fallPosY-j+1)*24;
                    tempLevel[numBlock*8+6] = (fallPosX+i)*24;
                    tempLevel[numBlock*8+7] = (fallPosY-j+1)*24;
                    for(int k = 0; k < 8; k++) tempTex[numBlock*8+k] = coord[1][k];
                }
                else
                {
                    tempLevel[numBlock*8  ] = (fallPosX+i)*24;
                    tempLevel[numBlock*8+1] = (fallPosY-j)*24;
                    tempLevel[numBlock*8+2] = (fallPosX+i+2)*24;
                    tempLevel[numBlock*8+3] = (fallPosY-j)*24;
                    tempLevel[numBlock*8+4] = (fallPosX+i+2)*24;
                    tempLevel[numBlock*8+5] = (fallPosY-j+1)*24;
                    tempLevel[numBlock*8+6] = (fallPosX+i)*24;
                    tempLevel[numBlock*8+7] = (fallPosY-j+1)*24;
                    for(int k = 0; k < 8; k++) tempTex[numBlock*8+k] = coord[0][k];
                }
                numBlock++;
            }

    Нямка. В унитаз уже не помещается, вылью сюда

    pelmenka, 07 Декабря 2013

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

    +28

    1. 1
    QVector<double*>*** ElemBoundCond = tbc->getElementsBC();

    Abbath, 06 Декабря 2013

    Комментарии (14)
  6. C++ / Говнокод #14189

    +16

    1. 1
    2. 2
    3. 3
    function<future<int> (int)> f = [](int a){ cout << a << '\n'; return mreturn(a + 6); };
    int a = (mreturn(5) >>= f).get();
    cout << a;

    HaskellGovno, 06 Декабря 2013

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

    +13

    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
    void Fetch_image::fetch(  ...
    						 , bool& image_repo_available)
    {
    	///...
    	if( smth)
    	{
    		/// ...
    		image_repo_available = false;/// 1
    		throw Exception( ...);/// 2
    	}
    	else
    	{
    		/// ...
    		image_repo_available = true;
    	}
    }
    
    bool Fetch_image::process(... ,bool& image_repo_available)
    {
    	/// ...
    	bool image_repo_available = false;
    	try
    	{
    		/// ...
    		fetch(..., image_repo_available);
    	}
    	catch(Exception const & ex)/// 3
    	{
    		log(...);
    		return false; /// 4
    	}
            catch (...)
            {
                    return false; /// 5
            }
    	/// ...
    }

    Параметры по ссылке
    ///1 устанавливаем значение
    ///2 бросаем исключение
    ///3 в catch ожидаем, что значение сохранится
    ///4 возврат из ф-ии
    И дальше по стеку еще 5 или 6 функций, которые принимают ссылку...


    Нахер так жить, котаны?

    blackhearted, 06 Декабря 2013

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

    +9

    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
    // fib.h
    #pragma once
    using ull = unsigned long long;
    
    inline constexpr ull fib(size_t n, ull first, ull second) {
      return n == 0 ? first : fib(n - 1, second, first + second);
    }
    
    inline constexpr ull fib(size_t n) {
      return fib(n, 0, 1);
    }
    // fibs.h
    #pragma once
    #include "fib.h"
    #include <array>
    
    enum class fibs : ull {
    #define FIB(i, val) fib##i = val,
    #define COUNT(val) COUNT = val
    #include "fibs.inl"
    #undef COUNT
    #undef FIB
    };
    
    std::array<ull, static_cast<size_t>(fibs::COUNT)> const & fibs_values() {
      static std::array<ull, static_cast<size_t>(fibs::COUNT)> values = {
    #define FIB(i, val) val,
    #define COUNT(val)
    #include "fibs.inl"
    #undef COUNT
    #undef FIB
      };
      return values;
    }
    // main.cpp
    #include "fibs.h"
    #include <iostream>
    
    int main() {
      using namespace std;
      for (auto fib : fibs_values()) {
        cout << fib << "," << endl;
      }
      return 0;
    }
    // fibs.inl = gen.exe > fibs.inl
    // gen.cpp
    #include "fib.h"
    #include <iostream>
    
    int main() {
      using namespace std;
      size_t i;
      for (i = 0; i < 94; i++) {
        cout << "FIB(" << i << ", " << fib(i) << ")" << endl;
      }
      cout << "COUNT(" << i << ")";
      return 0;
    }

    LispGovno, 04 Декабря 2013

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

    +13

    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
    auto write =    [&buf](future<int> size) -> future<bool>    { 
      return streamW.write(size.get(), buf).then(
        [](future<int> op){
          return op.get() > 0; });    };   
    auto flse = [](future<int> op){
     return future::make_ready_future(false);};  auto copy = do_while(
        [&buf]() -> future<bool>    {
         return streamR.read(512, buf)    .then(
           [](future<int> op){ return (op.get() > 0) ? write : flse;});    });  
    
    ///////////////////////////////////////////////////////////////////////////
    
    int cnt = 0;   
    do  {  
    cnt = await streamR.read(512, buf);   
    if ( cnt == 0 ) break;   
    cnt = await streamW.write(cnt, buf);   
    } while (cnt > 0);

    Первое и второе угадайте что? Правильно, С++. В компиляторе студии и первое и второе будет. Первое уже даже есть. Ни первое ни второе не приняли в стандарт на сколько мне известно и надеюсь лобисты Майкрософт во главе с Саттером пойдут на ... подальше от крестов.

    www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3722.pdf

    LispGovno, 03 Декабря 2013

    Комментарии (33)
  10. C++ / Говнокод #14172

    +8

    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
    void print(int i) {printf("int: %d\n", i);}
    void print(double f) {printf("double: %f\n", f);}
    void print(char const * c) {printf("str: %s\n", c);}
    
    void WTF(...) {}
    
    template<typename... T>
    void print(T ... t) 
    {
      WTF((print(t), 0)...);
    }
    
    int main()
    {
      print(1, "hello", 3.0);
      return 0;
    }

    http://ideone.com/wddRC7

    LispGovno, 03 Декабря 2013

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