- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
//g++ 4.9.3
#include <iostream>
int main()
{
for(int ang = 0; ang < 360; ang++)
{
int test = ang * 5981849;
std::cout << test << std::endl;
}
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+3
//g++ 4.9.3
#include <iostream>
int main()
{
for(int ang = 0; ang < 360; ang++)
{
int test = ang * 5981849;
std::cout << test << std::endl;
}
}
http://rextester.com/IHBA32841
+1
https://www.google.com/search?q=%D0%B2%D0%BE%D1%80%D0%B5%D1%86%D0%B8%D0%B8
Насрали так, что все ссылки ведут на говнокод.
Как эта херомантия называется в науке?
3.14159265359, это ты придумал слово "вореции"?
+3
#if defined(OSVR_WINDOWS)
static const auto SEARCH_PATH_ENV = "PATH";
static const auto SEARCH_PATH_SEP = ";";
#else
static const auto SEARCH_PATH_ENV = "LD_LIBRARY_PATH";
static const auto SEARCH_PATH_SEP = ":";
#endif
void wrappedPutenv(std::string const &val) {
#ifdef _MSC_VER
_putenv_s(SEARCH_PATH_ENV, val.c_str());
#else // not microsoft runtime specific
auto newValue = SEARCH_PATH_ENV + "=" + val;
// Have to allocate new string because it becomes part of the
// environment.
char *newString = static_cast<char *>(malloc(newValue.size() + 1));
std::copy(begin(newValue), end(newValue), newString);
#endif
}
Момент, когда я считаю, что C++-ный auto -- чистое зло(строка 14).
Код из OSVR-Vive, плагина к OSVR, который работает с HTC Vive.
+4
constexpr Fraction operator+(const Fraction& fraction) const noexcept
{
const Fraction max_fraction_by_denominator{denominator > fraction.denominator ? *this : fraction};
const Fraction min_fraction_by_denominator{denominator < fraction.denominator ? *this : fraction};
const bool is_sim_denominator = max_fraction_by_denominator.denominator %
min_fraction_by_denominator.denominator == 0;
int sim_denominator = is_sim_denominator ?
max_fraction_by_denominator.denominator : (max_fraction_by_denominator.denominator *
min_fraction_by_denominator.denominator);
const int nominator1 = is_sim_denominator ? (min_fraction_by_denominator.nominator *
max_fraction_by_denominator.denominator / min_fraction_by_denominator.denominator) :
min_fraction_by_denominator.nominator * max_fraction_by_denominator.denominator;
const int nominator2 = is_sim_denominator ? max_fraction_by_denominator.nominator :
max_fraction_by_denominator.nominator * min_fraction_by_denominator.denominator;
int nominators_sum = nominator1 + nominator2;
int while_parts_sum = while_part + fraction.while_part;
while (nominators_sum >= sim_denominator)
{
nominators_sum -= sim_denominator;
++while_parts_sum;
}
if (!nominators_sum)
sim_denominator = 0;
return {while_parts_sum, nominators_sum, sim_denominator};
}
+2
// TODO: Refactor to one call of 'refineIndexes'
std::vector<float32_t> *refined_left_1_3 = rec.refineIndexes(LEFT_CHANNEL, std::get<1>(p_l1) * ATT_3dB, INTERP_LINEAR, CROSS_RISE);
std::vector<float32_t> *refined_right_1_3 = rec.refineIndexes(RIGHT_CHANNEL, std::get<1>(p_r1) * ATT_3dB, INTERP_LINEAR, CROSS_RISE);
std::vector<float32_t> *refined_left_1_6 = rec.refineIndexes(LEFT_CHANNEL, std::get<1>(p_l1) * ATT_6dB, INTERP_LINEAR, CROSS_FALL);
std::vector<float32_t> *refined_right_1_6 = rec.refineIndexes(RIGHT_CHANNEL, std::get<1>(p_r1) * ATT_6dB, INTERP_LINEAR, CROSS_FALL);
std::vector<float32_t> *refined_left_2_3 = rec.refineIndexes(LEFT_CHANNEL, std::get<1>(p_l2) * ATT_3dB, INTERP_PARABOLIC, CROSS_RISE);
std::vector<float32_t> *refined_right_2_3 = rec.refineIndexes(RIGHT_CHANNEL, std::get<1>(p_r2) * ATT_3dB, INTERP_PARABOLIC, CROSS_RISE);
std::vector<float32_t> *refined_left_2_6 = rec.refineIndexes(LEFT_CHANNEL, std::get<1>(p_l2) * ATT_6dB, INTERP_PARABOLIC, CROSS_FALL);
std::vector<float32_t> *refined_right_2_6 = rec.refineIndexes(RIGHT_CHANNEL, std::get<1>(p_r2) * ATT_6dB, INTERP_PARABOLIC, CROSS_FALL);
bool exists_att_3dB = refined_left_1_3->size() > 0 && refined_right_1_3->size() > 0 && refined_left_2_3->size() > 0 && refined_right_2_3->size() > 0;
bool exists_att_6dB = refined_left_1_6->size() > 0 && refined_right_1_6->size() > 0 && refined_left_2_6->size() > 0 && refined_right_2_6->size() > 0;
if (exists_att_3dB || exists_att_6dB) {
float32_t rdTOA_l_3, rdTOA_r_3, rdBW_3, rdSW_3, rdTOA_l_6, rdTOA_r_6, rdBW_6, rdSW_6;
if (exists_att_3dB && !exists_att_6dB) {
rdTOA_l_6 = rdTOA_l_3 = refined_left_2_3->back() - refined_left_1_3->front();
rdTOA_r_6 = rdTOA_r_3 = refined_right_2_3->back() - refined_right_1_3->front();
rdBW_6 = rdBW_3 = refined_left_2_3->back() - refined_right_2_3->back();
rdSW_6 = rdSW_3 = refined_left_1_3->front() - refined_right_1_3->front();
}
else if (!exists_att_3dB && exists_att_6dB) {
rdTOA_l_6 = rdTOA_l_3 = refined_left_2_6->back() - refined_left_1_6->front();
rdTOA_r_6 = rdTOA_r_3 = refined_right_2_6->back() - refined_right_1_6->front();
rdBW_6 = rdBW_3 = refined_left_2_6->back() - refined_right_2_6->back();
rdSW_6 = rdSW_3 = refined_left_1_6->front() - refined_right_1_6->front();
}
else {
rdTOA_l_3 = refined_left_2_3->back() - refined_left_1_3->front();
rdTOA_r_3 = refined_right_2_3->back() - refined_right_1_3->front();
rdBW_3 = refined_left_2_3->back() - refined_right_2_3->back();
rdSW_3 = refined_left_1_3->front() - refined_right_1_3->front();
rdTOA_l_6 = refined_left_2_6->back() - refined_left_1_6->front();
rdTOA_r_6 = refined_right_2_6->back() - refined_right_1_6->front();
rdBW_6 = refined_left_2_6->back() - refined_right_2_6->back();
rdSW_6 = refined_left_1_6->front() - refined_right_1_6->front();
}
float32_t rdTOA_l = (rdTOA_l_3 + rdTOA_l_6) / 2f;
float32_t rdTOA_r =(rdTOA_r_3 + rdTOA_r_6) / 2f;
float32_t rdBW = (rdBW_3 + rdBW_6) / 2f;
float32_t rdSW = (rdSW_3 + rdSW_6) / 2f;
//TODO: Watch for group delay compensation!
float32_t rdeltaTOA = (rdTOA_l + rdTOA_r - 2 * groupDelay) / (2.0 * AUDIO_SAMPLE_RATE_EXACT);
float32_t rdeltaBlastWave = rdBW / AUDIO_SAMPLE_RATE_EXACT;
float32_t rdeltaShockWave = rdSW / AUDIO_SAMPLE_RATE_EXACT;
//..................................................
if (sd_init_status == SD_OK && current_settings.log) logFile.close();
refined_left_1_3->clear();
refined_right_1_3->clear();
refined_left_2_3->clear();
refined_right_2_3->clear();
refined_left_1_6->clear();
refined_right_1_6->clear();
refined_left_2_6->clear();
refined_right_2_6->clear();
delete refined_left_1_3;
delete refined_right_1_3;
delete refined_left_2_3;
delete refined_right_2_3;
delete refined_left_1_6;
delete refined_right_1_6;
delete refined_left_2_6;
delete refined_right_2_6;
50 часов без сна... Чувствую я пожалею завтра о том, что сегодня это написал.
+4
typedef class foo_c{
...
} foo_t;
Почему мне хочется использовать такой синтаксис?
+4
class Panel
{
// ...
friend class Panel;
// ...
}
Нашёл такое в хедерах VGUI1 -- игрового тулкита от Valve для Gold Source.
Объясните, умные люди, зачем?
−1
template<typename T>
T gcd(T a, T b) {
#pragma python(gcd)
while b != 0:
a, b = b, a % b
return a
}
всех с праздником, посоны
http://codeforces.com/blog/entry/44124
+6
#ifdef _WIN32
...
#elif defined __linux__
std::string path;
char buff[PATH_MAX];
ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff)-1);
if (len != -1)
{
buff[len] = '\0';
path = buff;
}
else
{
return -1;
}
int pos = path.rfind("/");
if (pos == std::string::npos)
return - 1;
path = path.substr(0, pos + 1);
path += "updater";
std::string sys_path = path;
boost::replace_all(sys_path, " ", "\\ ");
std::string rm = "rm -f ";
rm += sys_path;
system(rm.c_str());
_data.save_2_file(core::tools::from_utf8(path));
std::string chmod = "chmod 755 ";
chmod += sys_path;
system(chmod.c_str());
system(sys_path.c_str());
#endif //_WIN32
Как правильно обновлять #mailru/icqdesktop на Linux, если вы понимаете о чём я.
+8
template <size_t capacity, bool is_signed>
class fixed_int
{
// Описание ошибки компиляции в случае использования не поддерживаемой размерности
template <int x> struct unsupported_capacity { int i[1/(x-x)]; };
template <> struct unsupported_capacity<1> {};
template <> struct unsupported_capacity<2> {};
template <> struct unsupported_capacity<4> {};
template <> struct unsupported_capacity<8> {};
// Свойства базовых типов, необходимые для перебора
template<typename type> struct type_traits;
template<> struct type_traits <unsigned char> { typedef unsigned char current_type; typedef unsigned short next_type; };
template<> struct type_traits <unsigned short> { typedef unsigned short current_type; typedef unsigned int next_type; };
template<> struct type_traits <unsigned int> { typedef unsigned int current_type; typedef unsigned long next_type; };
template<> struct type_traits <unsigned long> { typedef unsigned long current_type; typedef unsigned long long next_type; };
template<> struct type_traits <unsigned long long int> { typedef unsigned long long int current_type; typedef unsupported_capacity<capacity> next_type; };
template<> struct type_traits <signed char> { typedef signed char current_type; typedef short next_type; };
template<> struct type_traits <short> { typedef short current_type; typedef int next_type; };
template<> struct type_traits <int> { typedef int current_type; typedef long next_type; };
template<> struct type_traits <long> { typedef long current_type; typedef long long next_type; };
template<> struct type_traits <long long int> { typedef long long int current_type; typedef unsupported_capacity<capacity> next_type;};
// Алгоритм выбора типа
template<typename type, bool>
struct type_choice
{
typedef typename type_traits<type>::current_type std_type;
};
template<typename type>
struct type_choice<type, false>
{
typedef typename type_traits<type>::next_type next_type;
typedef typename type_choice<next_type, sizeof(next_type) == capacity>::std_type std_type;
};
// Базовый тип для начала подбора
template <bool is_signed> struct base_type_selector { typedef signed char base_type; };
template <> struct base_type_selector<false> { typedef unsigned char base_type; };
public:
typedef typename type_choice< typename base_type_selector<is_signed>::base_type, sizeof(base_type_selector<is_signed>::base_type) == capacity >::std_type type;
};
"Зачем мне нужен stdint.h?
У меня нет времени, чтобы ебаться с ним!
Лучше я высру ещё десяток-другой шаблонов!"
https://habrahabr.ru/post/280542/
PS,
Пятая строка - вообще угар.