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

    +161

    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
    data::TokenPtr lexer::ReadToken::operator()(AnalyzeState analyze_state)
    {
        ReadTokenNum    handler01( nullptr  );
        ReadTokenName   handler02(&handler01);
        ReadTokenPlus   handler03(&handler02);
        ReadTokenMinus  handler04(&handler03);
        ReadTokenDiv    handler05(&handler04);
        ReadTokenMult   handler06(&handler05);
        ReadTokenAssign handler07(&handler06);
        ReadTokenSmcln  handler08(&handler07);
        ReadTokenLpar   handler09(&handler08);
        ReadTokenRpar   handler10(&handler09);
    
        ReadTokenHandler &start_handler = handler10;
    
        return
            start_handler.Read(analyze_state);
    }

    Вот такая красота получилась при использовании паттерна 'цепочка обязанностей'.

    int_index, 05 Ноября 2011

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

    +1002

    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
    template<class fwd, class Predicat>
    fwd findLast(fwd one, fwd last, Predicat P)
    {
              if (one == last) return one;
              fwd s = one;
              fwd tt = ++s;
              for ( ; s!=last; )
              { 
                   s = find_if(s, last, P);
                   if (s != last) { tt=++s;  }
              }
              return tt;
    }

    Функция для поиска последнего вхождения элемента в контейнере STL с помощью алгоритма find_if.

    Stanislaw374, 05 Ноября 2011

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

    +995

    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
    #include <stdio.h>
    #include <conio.h>
    #include <condefs.h>
     
    int main() {
    char str[]="любой текст";
    int i=0;
    while (str[i]!='\0') {
    printf("%c", str[i++]^100);
    if (str[i]=='\0') break;
    printf("%c", str[i++]|10);
    if (str[i]=='\0') break;
    printf("%c", str[i++]&400);
    if (str[i]=='\0') break;
    }
    printf("\n");
    getch();
    return 0;
    }

    Шифруется текст

    ITdocer, 03 Ноября 2011

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

    +162

    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
    /**/
    	TCHAR* szFileType = _T("");
    	int ftype = JGetByte( hContact, "AvatarType", PA_FORMAT_UNKNOWN );
    	if( ftype == PA_FORMAT_UNKNOWN ) {
    		WIN32_FIND_DATA ffd;
    		HANDLE hFind = FindFirstFile( ptszDest, &ffd );
    		if ( hFind != INVALID_HANDLE_VALUE ) {
    			wchar_t* szExt = m_strrchrs( ffd.cFileName, ".\\" );
    			if( szExt ) {
    				if( !_tcsicmp( szExt, _T(".jpg") ) )
    					ftype = PA_FORMAT_JPEG;
    				else if( !_tcsicmp( szExt, _T(".png") ) )
    					ftype = PA_FORMAT_PNG;
    				else if( !_tcsicmp( szExt, _T(".gif") ) )
    					ftype = PA_FORMAT_GIF;
    				else if( !_tcsicmp( szExt, _T(".bmp") ) )
    					ftype = PA_FORMAT_BMP;
    				if( ftype != PA_FORMAT_UNKNOWN )
    					JSetByte( hContact, "AvatarType", ftype );
    			}
    			FindClose( hFind );
    		}
    	}
    	switch( ftype ) {
    		case PA_FORMAT_JPEG: szFileType = _T("jpg");   break;
    		case PA_FORMAT_PNG:  szFileType = _T("png");   break;
    		case PA_FORMAT_GIF:  szFileType = _T("gif");   break;
    		case PA_FORMAT_BMP:  szFileType = _T("bmp");   break;
    	}

    http://infium.googlecode.com/svn/trunk/Jabber/jabber_misc.cpp

    bot-minurast, 03 Ноября 2011

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

    +1011

    1. 1
    #define RETURN_OR_THROW_EXCEPTION_IF_ERROR(Expression, Exception) if(!Expression) throw Exception; return Expression

    AnimeGovno-_-, 03 Ноября 2011

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

    +991

    1. 1
    unsigned long long int value=Bin<unsigned long long int>("1111111111111111111111111111111111111111111111111111111111111111");

    AnimeGovno-_-, 02 Ноября 2011

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

    +1009

    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
    #pragma once
    
    #include <vector>
    #include <algorithm>
    #include <exception>
    
    using namespace std;
    
    template<typename nodeT>
    class Tree
    {
    	Tree* root;
    	Tree(Tree* _root, nodeT value)
    		: root(_root)
    		, Node(value)
    	{
    	}
    	vector<Tree> children;
    public:
    	nodeT Node;
    	Tree(void) : root(nullptr) { }
    	Tree(const Tree& value)
    		: children(value.children)
    		, Node(value.Node)
    		, root(value.root)
    	{
    	}
    	virtual ~Tree(void) { }
    	const Tree& operator=(const Tree& value)
    	{
    		if(&value != this)
    		{
    			children = value.children;
    			for_each(children.begin(), children.end(), [this](Tree& tree)
    			{
    				tree.root = this;
    			});
    			Node = value.Node;
    			root = value.root;
    		}
    		return *this;
    	}
    	Tree& Root()
    	{
    		if(root == nullptr)
    		{
    			throw exception("already root");
    		}
    		return *root;
    	}
    	bool IsRoot() const
    	{
    		return root == nullptr;
    	}
    	Tree* Push(nodeT node)
    	{
    		children.push_back(Tree(this, node));
    		return &children.back();
    	}
    	Tree& operator[](typename vector<Tree>::size_type index)
    	{
    		return children[index];
    	}
    	vector<Tree*> Children()
    	{
    		vector<Tree*> result;
    		for(vector<Tree>::iterator i = children.begin(); i!=children.end(); i++)
    		{
    			result.push_back(&(*i));
    		}
    		return result;
    	}
    	typename vector<Tree>::iterator begin()
    	{
    		return children.begin();
    	}
    	typename vector<Tree>::iterator end()
    	{
    		return children.end();
    	}
    };

    Шаблон из http://govnokod.ru/6415.

    Xom94ok, 29 Октября 2011

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

    +150

    1. 1
    m_caster->HasAura(31866 || 31867 || 31868)

    из одного эмулятора WoW Cataclysm

    chaoswithin, 27 Октября 2011

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

    +1014

    1. 1
    2. 2
    3. 3
    4. 4
    if (strlen(Uid.c_str()) > 0)
    {
      // ...
    }

    собственно, std::string Uid;

    JeremyW, 27 Октября 2011

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

    +1002

    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
    Нужно написать функцию, возводящую число в 10 степень.
    
    Но почему, мой сотрудник обязательно напишет
    double func (double a) {
    return a * a * a * a * a * a * a * a * a * a;
    }
    ??????
    
    А когда понадобится 11 степень, он сделает так:
    double func (double a, bool is11 = false) {
    if (is11 == true)
    return a * a * a * a * a * a * a * a * a * a * a;
    return a * a * a * a * a * a * a * a * a * a;
    }
    
    А когда появится 12 степень, знаете что произойдет?
    double func (double a, int stepen = 0) {
    switch (stepen) {
    case 0: return a * a * a * a * a * a * a * a * a * a; break;
    case 1: return a * a * a * a * a * a * a * a * a * a * a; break;
    case 2: return a * a * a * a * a * a * a * a * a * a * a; break;
    }
    return 0;
    }

    Источник: http://ibash.org.ru/quote.php?id=14755

    rat4, 27 Октября 2011

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