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

    +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
    30. 30
    31. 31
    template < typename T >
    T shit (void)
    {
      return 0;
    }
    
    int main()
    {
      int crap = shit();
    // Почему дедукция аргумента шаблона в данном случае не работает?
      return crap;
    }
    
    //-------------------------------------
    
    int shit (void)
    {
      return 0;
    }
    
    // Почему functions that differ only in their return type cannot be overloaded 
    double shit (void)
    {
      return 0;
    }
    
    int main()
    {
      int crap = shit();
      return crap;
    }

    Почему плюсы такое говно?

    j123123, 22 Января 2018

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    https://www.reddit.com/r/cpp/comments/75gohf/i_just_found_a_use_for_the_poop_emoji_in_c/
    запостить этот говнокод непосредственно сюда не представляется возможным из-за юникодного символа говна:
    Application was halted by an exception.
    Debug-mode is off.

    I just found a use for the poop emoji in C++
    This actually detects whether the Visual Studio project has the proper UTF-8 flags set to compile it correctly.

    j123123, 16 Января 2018

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    bool switchToNext( SomeStdVectorTypedef& a )  {
        SomeInfo* info = this->getInfo();
        if ( ++info->i_current >= a.size() ) { // Порядок вычисления операндов тут, нужно ли после такого менять штаны?
            info->i_current = 0;
            return true;
        } else
            return false;
    }

    Некогда читать стандарт, поэтому решил накласть сюда сферический пример в ваккуме.
    Говнокод?

    OlegUP, 12 Января 2018

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

    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
    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
    #include <typeinfo>
    #include <string>
    #include <iostream>
    using namespace std::literals::string_literals;
    using std::cout;
    
    #if defined(__GNUG__) || defined(__clang__)
    #include <cxxabi.h>
    template <typename T>
    std::string get_real_type() {
    	int status;
    	char *real_name = abi::__cxa_demangle(typeid(T).name(), nullptr, nullptr, &status);
    	return (status == 0 ? std::string(real_name) : ("(not demangled)"s + typeid(T).name())); 
    }
    #else
    template <typename T>
    std::string get_real_type() {
    	return typeid(T).name();
    }
    #endif
    
    template <typename T>
    struct overload_generator {
    	std::string get_type_impl() {
    		return get_real_type<T>();
    	}
    };
    
    template <typename... Ts>
    struct printer : overload_generator<Ts>...
    {
    	using overload_generator<Ts>::get_type_impl...;
    	template<typename T>
    	void println_type() {
    		cout << overload_generator<T>::get_type_impl() << '\n';
    	}
    	template <typename... Us>
    	void println_types() {
    		println_types_impl((std::string(overload_generator<Us>::get_type_impl()) + "\n")...);
    	}
    private:
    	template <typename... Us>
    	void println_types_impl(Us... args) {
    		(cout << ... << args);
    	}
    };
    
    int main() {
    	auto pr = printer<int,long,decltype(nullptr)>();
    	pr.println_type<long>();
    	pr.println_types<long, decltype(nullptr),int>();
    }

    По мотивам http://govnokod.ru/23638#comment395579
    Разманглил имена, а то gcc выдает нечитаемую дичь в type_info::name для типов сложнее инта
    Ну и сахар из c++17 вроде свёртки аргументов вариативной шаблонной функции (fold expression, хз как лучше перевести) тут тоже есть

    eszett, 11 Января 2018

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

    +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
    constexpr auto auto​()
    {
      return 1;
    }
    
    typedef decltype(auto​()) auto​​;
    const auto​​ auto​​​ = auto​();
    
    template <typename auto​​​​>
    constexpr auto auto​​​​​() {
        return auto​​​;
    }
    
    template <typename auto​​​​, typename auto​​​​​​, typename... auto​​​​​​​>
    constexpr auto auto​​​​​() {
        return auto​​​ + auto​​​​​<auto​​​​​​, auto​​​​​​​...>();
    }
    
    int main()
    {
      constexpr auto auto​​​​​​​ = auto​​​​​<auto​​,auto​​,auto​​,auto​​,auto​​,auto​​>();
      constexpr auto auto​​​​ = auto​​​​​<auto​​,auto​​,auto​​,auto​​,auto​​,auto​​,auto​​>();
      return auto​​​​​​​*auto​​​​; 
    }

    auto auto auto...
    https://twitter.com/RichardKogelnig/status/943497972481953792
    https://godbolt.org/g/Yvczo1

    Soul_re@ver, 20 Декабря 2017

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

    +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
    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
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    #include <experimental/coroutine>
    #include <iostream>
    #include <optional>
    #include <utility>
    
    template<typename T>
    class Maybe
    {
        std::shared_ptr<std::optional<T>> m_maybe = std::make_shared<std::optional<T>>();
    public:
        Maybe() = default;
        
        Maybe(const T& t)
        : m_maybe { std::make_shared<std::optional<T>>(t) }
        {
        }
    
        explicit operator bool() const { return static_cast<bool>(*m_maybe); }
        T& operator* () { return **m_maybe; }
        const T& operator*() const { return **m_maybe; }
        
        void reset() { m_maybe->reset(); }
        
        template<typename U>
        void emplace(U&& u) { m_maybe->emplace(std::forward<U>(u)); }
    };
    
    template<typename T>
    void printMaybe(const Maybe<T>& opt)
    {
        if (opt)
            std::cout << *opt << std::endl;
        else
            std::cout << "<empty>" << std::endl;
    }
    
    template<typename T, typename... Args>
    struct std::experimental::coroutine_traits<Maybe<T>, Args...>
    {
        struct promise_type
        {
            Maybe<T> m_maybe;
            
            auto get_return_object() { return m_maybe; }
            
            std::experimental::suspend_never initial_suspend() { return {}; }
            std::experimental::suspend_never final_suspend() { return {}; }
            
            void unhandled_exception() { m_maybe.reset(); }
            
            template<typename U>
            void return_value(U&& u) { m_maybe.emplace(std::forward<U>(u)); }
        };
    };
    
    template<typename T>
    auto operator co_await(const Maybe<T>& maybe)
    {
        struct Awaiter
        {
            const Maybe<T>& input;
    
            bool await_ready() { return static_cast<bool>(input); }
            auto await_resume() { return *input; }
            void await_suspend(std::experimental::coroutine_handle<> coro) { coro.destroy(); }
        };
    
        return Awaiter { maybe };
    }
    
    Maybe<int> maybeAdd(const Maybe<int>& maybeA, const Maybe<int>& maybeB)
    {
        auto a = co_await maybeA;
        auto b = co_await maybeB;
        co_return a + b;
    }
    
    int main()
    {
      /*
        printMaybe(maybeAdd({ 1 }, { 2 }));
        printMaybe(maybeAdd({}, { 2 }));
        printMaybe(maybeAdd({ 1 }, {}));
        */
        const auto res = maybeAdd({ 1 }, { 2 });
        return res ? *res : 0;
    }

    do-нотация в плюсах

    j123123, 07 Декабря 2017

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

    −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
    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
    #include <iostream>
    using namespace std;
    /*Replace matricca's rows*/
    int** inputMatr(int** arr, unsigned m, unsigned n){
      for (unsigned i = 0; i < m; ++i)
        for (unsigned j = 0; j < n; ++j)
          cin >> arr[i][j];
      return arr;
    }
    int** outputMatr(int** arr, int m, int n){
      for (int i = 0; i < m; ++i){
        for (int j = 0; j < n; ++j)
         cout << arr[i][j] << " ";
         cout << endl;
      }
      return arr;
    }
    int** allocateMatr(unsigned m, unsigned n){
      int** p = new int*[m];
      for (unsigned i = 0; i < m; ++i)
        p[i] = new int[n];
      return p;
    }
    int** swapRows(int** arr, unsigned m, unsigned n){
         int** p = new int*[m];
      for (unsigned i = 0; i < m; ++i){
        p[i] = new int[n];
      }
    unsigned  ai=m;
    ai--;
        for (unsigned i = 0; i < m/2; i++,ai--){
        for (unsigned j = 0; j < n; j++){
          p[i][j]= arr[i][j];
          arr[i][j]=arr[ai][j];
          arr[ai][j]=p[i][j];
        }
        }
      return arr;
      }
    int main() {
        int row,column;
      cout << "Input size  matr " << endl;
      cin >> row >> column;
      int** array = allocateMatr(row,column); 
      inputMatr(array,row ,column);
      swapRows(array,row,column);
       outputMatr(array, row ,column);
    	return 0;
    }

    Поменять строки матрицы(1ую с последней,вторую с предпоследней и т.д)

    ArthurMakaev, 06 Декабря 2017

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

    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
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    PrefixAllocator::PrefixAllocator(
        const std::string& myNodeName,
        const KvStoreLocalCmdUrl& kvStoreLocalCmdUrl,
        const KvStoreLocalPubUrl& kvStoreLocalPubUrl,
        const PrefixManagerLocalCmdUrl& prefixManagerLocalCmdUrl,
        const MonitorSubmitUrl& monitorSubmitUrl,
        const AllocPrefixMarker& allocPrefixMarker,
        const folly::Optional<folly::CIDRNetwork> seedPrefix,
        uint32_t allocPrefixLen,
        bool setLoopbackAddress,
        bool overrideGlobalAddress,
        const std::string& loopbackIfaceName,
        std::chrono::milliseconds syncInterval,
        PersistentStoreUrl const& configStoreUrl,
        fbzmq::Context& zmqContext)
        : myNodeName_(myNodeName),
          allocPrefixMarker_(allocPrefixMarker),
          seedPrefix_(seedPrefix),
          allocPrefixLen_(allocPrefixLen),
          setLoopbackAddress_(setLoopbackAddress),
          overrideGlobalAddress_(overrideGlobalAddress),
          loopbackIfaceName_(loopbackIfaceName),
          syncInterval_(syncInterval),
          configStoreClient_(configStoreUrl, zmqContext),
          zmqMonitorClient_(zmqContext, monitorSubmitUrl) {

    Фейсбук выложил какую-то хуйню https://github.com/facebook/openr/blob/master/openr/allocators/PrefixAllocator.cpp#L61

    g0cTb, 16 Ноября 2017

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

    0

    1. 1
    https://webhamster.ru/mytetrashare/index/mtb0/1480776952mrczr7xk44

    Какие изменения предлагает инициативная группа стандарта C++!!, чтобы сделать язык C++ красивым, мощным и востребованным средством современной разработки?

    j123123, 10 Ноября 2017

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

    +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
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    // https://github.com/telegramdesktop/tdesktop/blob/5f5770dd46491133b135a71fc2d4f92d13107ade/Telegram/SourceFiles/history.cpp#L1455
    
    int History::countUnread(MsgId upTo) {
    	int result = 0;
    	for (auto i = blocks.cend(), e = blocks.cbegin(); i != e;) {
    		--i;
    		for (auto j = (*i)->items.cend(), en = (*i)->items.cbegin(); j != en;) {
    			--j;
    			if ((*j)->id > 0 && (*j)->id <= upTo) {
    				break;
    			} else if (!(*j)->out() && (*j)->unread() && (*j)->id > upTo) {
    				++result;
    			}
    		}
    	}
    	return result;
    }
    
    void History::updateShowFrom() {
    	if (showFrom) return;
    
    	for (auto i = blocks.cend(); i != blocks.cbegin();) {
    		--i;
    		for (auto j = (*i)->items.cend(); j != (*i)->items.cbegin();) {
    			--j;
    			if ((*j)->id > 0 && (!(*j)->out() || !showFrom)) {
    				if ((*j)->id >= inboxReadBefore) {
    					showFrom = *j;
    				} else {
    					return;
    				}
    			}
    		}
    	}
    }

    очередная порция говнеца из телесрамного клиента

    j123123, 07 Ноября 2017

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