1. Список говнокодов пользователя rudvil

    Всего: 5

  2. C++ / Говнокод #4197

    +155

    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
    typedef struct IS_THIS_AN_ARRAY_OR_A_NULL_TERMINATED_STRING344 : boost::mpl::assert_ {
    
      static boost::mpl::failed ************ (IS_THIS_AN_ARRAY_OR_A_NULL_TERMINATED_STRING::************ assert_arg()) (T&) {
        return 0;
      }
    } mpl_assert_arg344;
    
    typedef struct IS_THIS_AN_ARRAY_OR_A_NULL_TERMINATED_STRING375 : boost::mpl::assert_ {
    
      static boost::mpl::failed ************ (IS_THIS_AN_ARRAY_OR_A_NULL_TERMINATED_STRING::************ assert_arg()) (T&) {
        return 0;
      }
    } mpl_assert_arg375;
    
    template< typename Pred >
    failed ************ (Pred::************
      assert_arg(void (*)(Pred), typename assert_arg_pred<Pred>::type)
      );
    
    template< typename Pred >
    failed ************ (boost::mpl::not_<Pred>::************
      assert_not_arg(void (*)(Pred), typename assert_arg_pred_not<Pred>::type)
      );

    В том что boost'овские библиотеки достаточно хорошо оптимизированы я не сомневаюсь, но от некоторых конструкций я просто охреневаю...

    rudvil, 08 Сентября 2010

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

    +158

    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
    const char* def = "DEFINE";
    while(*def && (m_position != m_end) && (*m_position == charT(*def)))
      ++m_position, ++def;
    if((m_position == m_end) || *def)
    {
      // Rewind to start of (? sequence:
      --m_position;
      while(this->m_traits.syntax_type(*m_position) != regex_constants::syntax_open_mark) --m_position;
      fail(regex_constants::error_perl_extension, m_position - m_base);
      return false;
    }
    re_brace* br = static_cast<re_brace*>(this->append_state(syntax_element_assert_backref, sizeof(re_brace)));
    br->index = 9999; // special magic value!
    if(this->m_traits.syntax_type(*m_position) != regex_constants::syntax_close_mark)
    {
      // Rewind to start of (? sequence:
      --m_position;
      while(this->m_traits.syntax_type(*m_position) != regex_constants::syntax_open_mark) --m_position;
      fail(regex_constants::error_perl_extension, m_position - m_base);
      return false;
    }

    Фрагмент из boost::regex, "magic value!", улыбнуло =]
    basic_regex_parser.hpp : 2160

    rudvil, 28 Августа 2010

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

    +164

    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
    std::string str(bool val) {
      std::stringstream ss;
      ss << val;
      return ss.str();
    }
    
    std::string str(short val) {
      std::stringstream ss;
      ss << val;
      return ss.str();
    }
    
    std::string str(unsigned short val) {
      std::stringstream ss;
      ss << val;
      return ss.str();
    }
    
    std::string str(int val) {
      std::stringstream ss;
      ss << val;
      return ss.str();
    }
    
    std::string str(unsigned int val) {
      std::stringstream ss;
      ss << val;
      return ss.str();
    }
    
    std::string str(long val) {
      std::stringstream ss;
      ss << val;
      return ss.str();
    }
    
    std::string str(unsigned long val) {
      std::stringstream ss;
      ss << val;
      return ss.str();
    }
    
    std::string str(float val) {
      std::stringstream ss;
      ss << val;
      return ss.str();
    }
    
    std::string str(double val) {
      std::stringstream ss;
      ss << val;
      return ss.str();
    }
    
    std::string str(long double val) {
      std::stringstream ss;
      ss << val;
      return ss.str();
    }

    Вот что значит невыспанная голова!
    Чуть позже переделал в это

    template<class T>
    std::string str(T val) {
    std::stringstream ss;
    ss << val;
    return ss.str();
    }

    rudvil, 14 Июля 2010

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

    +974

    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
    /*Вариант - вручную*/
    #include <iostream>
    #include <map>
    #include <string>
    #include <utility>
    
    int main(int argc, char* argv[]) {
      std::map<std::string, std::pair<int, int> > files;
      files["0.txt"] = std::make_pair(0, 7);
      files["1.txt"] = std::make_pair(8, 41);
      files["2.txt"] = std::make_pair(42, 50);
      std::map<std::string, std::pair<int, int> >::const_iterator begin = files.begin();
      std::map<std::string, std::pair<int, int> >::const_iterator end = files.end();
      int num = 21;
      for (; begin != end; ++begin) {
        if (num >= (*begin).second.first && num <= (*begin).second.second) {
          std::cout << "Found in " + (*begin).first + "\n";
          break;
        }
      }
      return 0;
    }
    
    /*Вариант - STL+BOOST*/
    #include <algorithm>
    #include <functional>
    #include <iostream>
    #include <map>
    #include <string>
    #include <utility>
    
    #include <boost/bind.hpp>
    
    int main(int argc, char* argv[]) {
      typedef std::map<std::string, std::pair<int, int> > map_type;
      map_type files;
      files["0.txt"] = std::make_pair(0, 7);
      files["1.txt"] = std::make_pair(8, 41);
      files["2.txt"] = std::make_pair(42, 50);
      int num = 21;
      map_type::const_iterator elem;
      elem = std::find_if(
                          files.begin(),
                          files.end(),
                          boost::bind(
                                      std::logical_and<bool>(),
                                      boost::bind(
                                                  std::less_equal<int>(),
                                                  boost::bind(
                                                              &map_type::value_type::second_type::first,
                                                              boost::bind(
                                                                          &map_type::value_type::second,
                                                                          _1)
                                                              ),
                                                  num),
                                      boost::bind(
                                                  std::greater_equal<int>(),
                                                  boost::bind(
                                                              &map_type::value_type::second_type::second,
                                                              boost::bind(
                                                                          &map_type::value_type::second,
                                                                          _1)
                                                              ),
                                                  num)));
      if (elem != files.end())
        std::cout << "Found in " + (*elem).first + "\n";
      return 0;
    }

    Смысл в том, чтобы с данным значением(пример 21) пройтись по таблице и найти в каком элементе данное число(21) находится в диапазоне std::pair<int, int>...
    Сначала написал вручную, но т.к. нужно было сделать с помощью STL, получилось сие чудо.

    rudvil, 13 Мая 2010

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

    +103

    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
    #include <iostream>
    #include <string>
    #include <boost/foreach.hpp>
    
    int main(int argc, char* argv[]) {
      std::string str = "Boost FOREACH!";
      char ch;
      if (boost::foreach_detail_::auto_any_t _foreach_col11 = boost::foreach_detail_::contain( ( str ) , (true ? 0 : boost::foreach_detail_::or_( boost::foreach_detail_::and_( boost::foreach_detail_::not_(boost::foreach_detail_::is_array_( str )) , (true ? 0 : boost::foreach_detail_::is_rvalue_( (true ? boost::foreach_detail_::make_probe( str ) : ( str )), 0))) , boost::foreach_detail_::and_( boost::foreach_detail_::not_( boost_foreach_is_noncopyable( boost::foreach_detail_::to_ptr( str ) , boost_foreach_argument_dependent_lookup_hack_value) ) , boost_foreach_is_lightweight_proxy( boost::foreach_detail_::to_ptr( str ) , boost_foreach_argument_dependent_lookup_hack_value)) )) ) ) {} else if (boost::foreach_detail_::auto_any_t _foreach_cur11 = boost::foreach_detail_::begin( _foreach_col11 , (true ? 0 : boost::foreach_detail_::encode_type( str , boost::foreach_detail_::is_const_( str ))) , (true ? 0 : boost::foreach_detail_::or_( boost::foreach_detail_::and_( boost::foreach_detail_::not_(boost::foreach_detail_::is_array_( str )) , (true ? 0 : boost::foreach_detail_::is_rvalue_( (true ? boost::foreach_detail_::make_probe( str ) : ( str )), 0))) , boost::foreach_detail_::and_( boost::foreach_detail_::not_( boost_foreach_is_noncopyable( boost::foreach_detail_::to_ptr( str ) , boost_foreach_argument_dependent_lookup_hack_value) ) , boost_foreach_is_lightweight_proxy( boost::foreach_detail_::to_ptr( str ) , boost_foreach_argument_dependent_lookup_hack_value)) )) ) ) {} else if (boost::foreach_detail_::auto_any_t _foreach_end11 = boost::foreach_detail_::end( _foreach_col11 , (true ? 0 : boost::foreach_detail_::encode_type( str , boost::foreach_detail_::is_const_( str ))) , (true ? 0 : boost::foreach_detail_::or_( boost::foreach_detail_::and_( boost::foreach_detail_::not_(boost::foreach_detail_::is_array_( str )) , (true ? 0 : boost::foreach_detail_::is_rvalue_( (true ? boost::foreach_detail_::make_probe( str ) : ( str )), 0))) , boost::foreach_detail_::and_( boost::foreach_detail_::not_( boost_foreach_is_noncopyable( boost::foreach_detail_::to_ptr( str ) , boost_foreach_argument_dependent_lookup_hack_value) ) , boost_foreach_is_lightweight_proxy( boost::foreach_detail_::to_ptr( str ) , boost_foreach_argument_dependent_lookup_hack_value)) )) ) ) {} else for (bool _foreach_continue11 = true; _foreach_continue11 && ! boost::foreach_detail_::done( _foreach_cur11 , _foreach_end11 , (true ? 0 : boost::foreach_detail_::encode_type( str , boost::foreach_detail_::is_const_( str ))) ) ; _foreach_continue11 ? boost::foreach_detail_::next( _foreach_cur11 , (true ? 0 : boost::foreach_detail_::encode_type( str , boost::foreach_detail_::is_const_( str ))) ) : (void)0) if (boost::foreach_detail_::set_false( _foreach_continue11 )) {} else for ( ch = boost::foreach_detail_::deref( _foreach_cur11 , (true ? 0 : boost::foreach_detail_::encode_type( str , boost::foreach_detail_::is_const_( str ))) ) ; ! _foreach_continue11 ; _foreach_continue11 = true) {
        std::cout << ch;
      }
      std::cout << std::endl;
      return 0;
    }

    Конечно, это не совсем говнокод, но... я офигел когда посмотрел во что превращается простой BOOST_FOREACH

    rudvil, 03 Мая 2010

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