- 1
- 2
- 3
- 4
switch (true)
{
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
switch (true)
{
}
+1
http://pragmaticperl.com/issues/26/pragmaticperl-26-грамматики-в-perl-6.html
:3
Где еще такое может быть то?
+1
#include <stdio.h>
#include <stdlib.h>
void myfree(void *ptr)
{
printf("%p\n", *(void **)ptr);
free(*(void **)ptr);
printf("freed!\n");
}
int main(void) {
char *x __attribute__ (( cleanup (myfree) )) = malloc(1);
printf("%p\n", x);
return 0;
}
https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
cleanup (cleanup_function)
The cleanup attribute runs a function when the variable goes out of scope. This attribute can only be applied to auto function scope variables; it may not be applied to parameters or variables with static storage duration. The function must take one parameter, a pointer to a type compatible with the variable. The return value of the function (if any) is ignored.
If -fexceptions is enabled, then cleanup_function is run during the stack unwinding that happens during the processing of the exception. Note that the cleanup attribute does not allow the exception to be caught, only to perform an action. It is undefined what happens if cleanup_function does not return normally.
+1
for i in for i in itertools.count():
# ...
if i >= x:
break
+1
#include <iostream>
#include <functional>
#include <array>
#include <iterator>
template <class T>
class Filter : public std::iterator<
std::input_iterator_tag,
typename std::iterator_traits<T>::value_type,
typename std::iterator_traits<T>::difference_type,
typename std::iterator_traits<T>::pointer,
typename std::iterator_traits<T>::reference
>
{
private:
typedef typename std::iterator_traits<T>::value_type value_type;
std::function<bool(value_type)> m_predicate;
T m_begin, m_end;
value_type m_current;
public:
Filter(T t_begin, T t_end, std::function<bool(value_type)> t_predicate)
: m_begin(t_begin), m_end(t_end), m_predicate(t_predicate)
{
}
Filter<T>& begin()
{
return ++*this;
}
Filter<T>& end()
{
return *this;
}
value_type operator* ()
{
return m_current;
}
Filter<T>& operator++ ()
{
do {
m_current = *m_begin;
++m_begin;
} while (m_begin != m_end && !m_predicate(m_current));
return *this;
}
bool operator!= (Filter<T>& t_right)
{
return m_begin != t_right.m_end;
}
};
int main()
{
std::array<int, 10> arr{ {4, 35, 0, 23, 0, 0, 5} };
for (auto i : Filter<typename std::array<int,10>::iterator>(arr.begin(), arr.end(), [](int x){return x != 0;})) {
std::cout << i << " ";
}
}
+1
function getCartMiniViewDisplayString($cart_entries) {
$count = $cart_entries->getProductCount();
$suffix = "";
$remainder = $count % 10;
switch($remainder) {
case 1:
$suffix = " товар";
break;
case 2:
case 3:
case 4:
$suffix = " товара";
break;
case 5:
case 6:
case 7:
case 8:
case 9:
case 0:
$suffix = " товаров";
break;
}
return $count . $suffix;
}
Мой, переписывать с if в лень.
+1
else {
// на всякий случай возвращаем true в случае некоторых экзотических браузеров
flashinstalled = true;
}
return flashinstalled;
https://csdrop.org/
main.js
Просто из за комментария ☺
+1
https://en.cppreference.com/w/cpp/language/lambda
> Explanation
> > <tparams>
> Like in a template declaration, the template parameter list may be followed by an optional requires-clause, which specifies the constraints on the template arguments.
> optional requires-clause
небязательные обязательные пункты.
Переводил почти час.
+1
Вы такого еще не видали
https://paste.ubuntu.com/p/gpsMVPnd6T/
Отформатировано: https://paste.ubuntu.com/p/vF8hCGN6Z3/
20 уровней индентации, адовый копипаст.
+1
foreach ($result->getDataCollection() as $data) {
if (!$data->getStatus() === Status::PAID)
continue;
// ACTIONS
}
Зачем использовать !== если есть ===
P/s
Смотрим на if (