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

    +19

    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
    // хелпер чтобы конвертить типы строк
    template <class S1, class S2>
    struct str_convert {
    	static S1 conv(S2 const & s2) { return str_convert<S2, S1>::conv(s2); }		// по умолчанию ищет специализацию для пары S2, S1
    	static S2 conv(S1 const & s1) { return str_convert<S2, S1>::conv(s1); }
    };
    
    // специализация, чтобы не конвертить одно в одно
    template <class S>
    struct str_convert<S, S> {
    	static S const & conv(S const & s) { return s; };
    };
    
    // специализация, чтобы конвертить std::string <-> std::wstring
    template <>
    struct str_convert<std::string, std::wstring> {
    	static std::string conv(std::wstring const & ws) { return boost::locale::conv::utf_to_utf<char>(ws); }
    	static std::wstring conv(std::string const & s)  { return boost::locale::conv::utf_to_utf<wchar_t>(s); }
    };
    
    // специализация QString <-> std::string
    // skipped
    
    template <class StringType = std::string>
    struct some 
    {
    	typedef StringType		string_type;
    	typedef std::string		utf8_string_type;
    
    	some(string_type const & s = string_type())
    		: inner_string_(s)
    	{}
    
    	template <class S>
    	some(S const & s)
    		: inner_string_(str_convert<S, string_type>::conv(s))
    	{}
    
    	string_type inner_string_;
    };
    
    int main()
    {
    	std::string s = "hello!";
    	some<> test0(s);		  // ok
    	some<> test2("hello!"); // ха-ха, вот еще, пытаться самостоятельно привести к std::string, пиши специализацию для массивов, сука!
    	return 0;
    }

    сегодня ради красоты передачи "literal" в конструктор писал говноспециализации для PodType[N]

    defecate-plusplus, 04 Июля 2012

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

    +23

    1. 1
    2. 2
    if(this==NULL)
      return;

    HaskellGovno, 04 Июля 2012

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

    +5

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    template<class T>
    bool IsAligned(T SizeOrAddress, const size_t AlignStep)
    {
    	return SizeOrAddress==Align(SizeOrAddress, AlignStep);
    }

    HaskellGovno, 03 Июля 2012

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

    +15

    1. 1
    void* const allocateOrDie(const size_t Size) throw();

    Ультиматум. :)

    HaskellGovno, 03 Июля 2012

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

    +12

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if(maxbits<3) x = genrand64_int64() & genrand64_int64() & genrand64_int64() & genrand64_int64() & genrand64_int64();
    				else 
    				{
    					if(maxbits<6) x = genrand64_int64() & genrand64_int64() & genrand64_int64() & genrand64_int64();
    					else x = genrand64_int64() & genrand64_int64() & genrand64_int64();
    				}

    Fai, 03 Июля 2012

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

    +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
    class SumClass
    {
      int A, B;
      public:
      void Set_A(int A) {this->A = A;}
      void Set_B(int B) {this->B = B;}
    
      int Sum() {return A+B;}
    }
    
    class MultiSumClass
    {
      SumClass Sum;
      int count;
      public:
      void Set_A(int A) {Sum.Set_A(A);}
      void Set_B(int B) {Sum.Set_B(B);}
      void Set_Count(int count) {this->count = count;}
      
      int GetSum() {return Sum->Sum()*count;}
    }
    
    void main()
    {
       MultiSumClass MSC;
       MSC.Set_A(5); MSC.Set_B(10);
       MSC.Set_Count(2);
       cout << MSC.GetSum();
    }

    Вот зачем ООП нужно
    http://www.gamedev.ru/flame/forum/?id=164035

    извените за игрстрй

    TarasB, 02 Июля 2012

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

    −11

    1. 1
    rampage=1<<12;

    Видимо кто-то из буйных писал.

    HaskellGovno, 02 Июля 2012

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    WORD StrLen(PChar s)
    {
    	ASSERT(s!=NULL);
    	int i;
    	for (i=0; ( (*(s+i)!=0) && (i<=WORDMAX) ); i++) {};
    	ASSERT(i<=WORDMAX);
    	return (WORD)i;
    };

    По заявкам из http://govnokod.ru/11318

    Говногость, 29 Июня 2012

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

    −18

    1. 1
    return StrLen((*i).second);

    В точку.

    Говногость, 29 Июня 2012

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

    −16

    1. 1
    2. 2
    3. 3
    void setOn(const bool &on) {
        // ...
    }

    А вот чего только не встретишь в коде...

    glook, 29 Июня 2012

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