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

    +5

    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
    void add( std::string *str, std::string *addstr)
    {
      if(!strlen(addstr->c_str()))
        return;
    
      int len = strlen(str->c_str());
      if( len )
      {
        if((str->c_str())[len-1] != ';')
          *str = *str + ";";
    
        *str = *str + *addstr;
      }
      else
        *str = *addstr;
    
      len = strlen(str->c_str());
      if((str->c_str())[len-1] == ';')
    
      *str = str->substr(0,len-1);
    }

    kocmoc, 15 Июля 2016

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

    +3

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    #include <iostream>
    #include <vector>
    using namespace std;														
    
    
    int main() {
    	victor<bull> v = {1,0,1};
    	for(auto&& i : v) //Если удалить один &, то не скомпилируется
    		cout<<i<<endl;
    	return 0;
    }

    http://rextester.com/DBCM68277

    laMer007, 13 Июля 2016

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

    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
    SoftwareCommon::params::IParamLoader::TypeDb SettingsProxy::getTypeDb() const
    	{
    		try
    		{
    			auto type = Locator::Services::Locator->Resolve<ISettings^>()->Type;
    			switch (type)
    			{
    			case decltype(type)::Firebird: return IParamLoader::Firebird;
    			case decltype(type)::MSSQL: return IParamLoader::MSSQL;
    			default:
    				throw std::runtime_error("Unsupported db type");
    			}
    		}
    		catch (Exception ^ex)
    		{
    			throw std::runtime_error(marshal_1251(ex->ToString()));
    		}
    	}

    laMer007, 13 Июля 2016

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

    +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
    // p2.cpp : Defines the entry point for the console application.
    //   Язык Visual C++ 7.0
    //   Консольное приложение
    //   13.07.2016
    
    #include "stdafx.h"
    #include <conio.h>
    
    int aa (int, int, int);
    void ab (int);
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	int a, b, c, d, e;
    	int f;
    
    	for (a = 0; a < 4; a++)
    		for (b = 0; b < 4; b++)
    			for (c = 0; c < 4; c++)
    				for (d = 0; d < 4; d++)
    					for (e = 0; e < 4; e++)
    					{
    						f = aa (1, a, 2);
    						f = aa (f, b, 3);
    						f = aa (f, c, 4);
    						f = aa (f, d, 5);
    						f = aa (f, e, 6);
    
    						if (f == 35)
    						{
    							printf ("((((1 "); ab (a);
    							printf ("2) "); ab (b);
    							printf ("3) "); ab (c);
    							printf ("4) "); ab (d);
    							printf ("5) "); ab (e);
    							printf ("6 = 35.\n");
    						}
    					}
    
    	getch ();
    	return 0;
    }
    
    
    int aa (int a, int b, int c)
    {
    	switch (b)
    	{
    		case 0: return a + c;
    		case 1: return a - c;
    		case 2: return a * c;
    		case 3: return a / c;
    	}
    
    	return 0;
    }
    
    void ab (int a)
    {
    	switch (a)
    	{
    		case 0: printf ("+ "); break;
    		case 1: printf ("- "); break;
    		case 2: printf ("* "); break;
    		case 3: printf ("/ "); break;
    	}
    }

    Задача: В написанном выражении ((((1 ? 2) ? 3) ? 4) ? 5) ? 6 вместо каждого знака ? вставить знак одного из четырёх арифметических действий: +, -, *, / так, чтобы результат вычислений равнялся 35.

    FrontlineReporter, 13 Июля 2016

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

    +4

    1. 1
    2. 2
    auto highPriority = static_cast<bool>(features(w)[5]);
    // Тип features(w) - std::vector<bool>

    Скотт Майерс. Эффективный и современный С++.

    Antervis, 10 Июля 2016

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

    +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
    enum SomeEnum
    {
        // ...
        SomeShit = 0xD6,
        // ...
    };
    
    // ....
    
        Byte opcode = ReadSomeShit<Byte>();  // функция читающая raw memory в нужном представлении
        // из raw memory считано значение эквивалентное 0xD6
        // ...
        if (opcode == SomeShit) // условие не выполнилось
        {
            // do stuff
        }
    
    // ...

    почему? а потому что кто додумался до
    typedef char Byte;
    который (хоть и не обязан быть, но) знаковый

    и даже сраного ворнинга не выдало
    причина правда обнаружилась достаточно быстро, ибо в дебагере в opcode красовалось -42 а в SomeShit 214

    https://ideone.com/02TpT7 на первый взгляд вызывает когнитивный диссонанс
    обожаю кресты

    meinf, 08 Июля 2016

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

    +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
    #include <iostream>
    #include <stdexcept>
    
    using namespace std;
    
    class Exception : std::runtime_error
    {
    public:
        Exception( std::string const & what ) : std::runtime_error(what)
        {
        }
    };
    
    int main( )
    {
        try
        {
            throw Exception("Exception");
        }
        catch ( std::exception const & e )
        {
            std::cerr << e.what() << std::endl;
        }
        catch(...)
        {
            std::cerr << "..." << std::endl;
        }
        return 0;
    }

    laMer007, 08 Июля 2016

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

    +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
    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
    #include <iostream>
    using namespace std;
     
    class Boolean {
    public:
        Boolean() : m_flag(false), m_val(0) {}
        Boolean(bool flag) : m_flag(flag), m_val(0) {}
        Boolean(bool flag, int val) : m_flag(flag), m_val(val) {}
     
        Boolean operator || (int val) {
            return Boolean(m_flag || val == m_val, m_val);
        }
     
        operator bool() { return m_flag; }
     
    private:
        bool m_flag;
        int m_val;
    };
     
    class Integer {
    public:
        Integer() : m_val(0) {}
        Integer(int val) : m_val(val) {}
     
        operator int() { return m_val; }
        Boolean operator == (int val) { return Boolean(val == m_val, m_val); }
        Boolean operator == (const Integer & val) { return Boolean(val.m_val == m_val, m_val); }
     
    private:
        int m_val;
    };
     
    int main() {
        Integer a(10);
     
        cout << bool(a == 15 || 10) << endl;
        cout << bool(a == 15 || 11) << endl;
        cout << bool(a == 15 || 11 || 13 || 11 || 0 || 10 || 5) << endl;
        cout << bool(a == 15 || 11 || 13 || 11 || 0 || 9 || 5) << endl;
     
        return 0;
    }

    https://ideone.com/xwMvx7

    gost, 07 Июля 2016

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

    +3

    1. 1
    Point3D& operator /= (const float f) { x/=f; y/=f; z/=f; return *this; }

    ебать я лох

    TarasB, 06 Июля 2016

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

    +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
    template<class... Bases>
    struct MaminVisitor: public boost::static_visitor<>, public Bases... {
        MaminVisitor(Bases&&... bases) : Bases(std::move(bases))... { }
    };
    
    
    template<class Variant, class... F>
    void match(Variant &&v, F &&... functors) {
        typedef MaminVisitor<typename std::decay<F>::type...> visitor_t;
        boost::apply_visitor(visitor_t(std::move(functors)...), std::forward<Variant>(v));
    }
    
    
    int main() {
        boost::variant<int, double, std::string> v = "ololo";
    
        match(v,
            [&](auto x) {
                std::cout << "auto branch " << x << std::endl;
            },
            [&](double x) {
                std::cout << "double branch " << x << std::endl;
            }
        );
    
        return 0;
    }

    Сделал няшный матч, а на гцц не конпелируется.
    http://ideone.com/J9ulsr

    kurwa-nextgen, 05 Июля 2016

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