- 1
- 2
- 3
- 4
- 5
- 6
- 7
// OK
class foo {};
void foo();
// не ОК: error: 'void bar()' redeclared as different kind of symbol
namespace bar {}
void bar();
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
// OK
class foo {};
void foo();
// не ОК: error: 'void bar()' redeclared as different kind of symbol
namespace bar {}
void bar();
"Двойные стандарты"
+4
template<class T, T = 1>
constexpr bool __can_one(int) { return true; };
template<class T>
constexpr bool __can_one(long) { return false; };
template <class T>
constexpr bool is_integral_v = __can_one<T>(0);
https://twitter.com/ericniebler/status/976524085927731200
Не кто попало, а автор Ranges TS (без пяти минут кусок стандарта) сомневается, валидную метушню он написал или нет. Пора уже создавать крестоблядский суд, который будет трактовать букву стандарта и решать, где с++ а где нет. И разрабы гцц будут нанимать за бешеное бабло крестоблядских юристов и судиться в крестоблядском суде с авторами багрепортов.
0
//Они относятся к посту ниже
#include "stdafx.h"
#include<iostream>
using namespace std;
/*Доказать что (АВ)^-1=B^-1*A^-1*/
void printLine(int n) {
n *= 2;
n--;
for (int i = 0; i < n;i++) {
cout << '*';
}
cout << endl;
}
void obr(bool **arr1,bool **arr2, int m, int n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
arr2[i][j]=arr1[j][i];
//cout << arr1[j][i];
//cout << ' ';
}
//cout << endl;
}
}
void obr(bool **arr1, int m, int n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << arr1[j][i];
cout << ' ';
}
cout << endl;
}
}
void multiple(bool **arr1, bool **arr2,bool **tempAr, int m, int n) {
for (int i = 0; i < m; i++) {
for (int j = 0;j < n; j++) {
tempAr[i][j]= arr1[i][j]* arr2[i][j];
cout << tempAr[i][j];
cout << ' ';
}
cout << endl;
}
}
void multiple(bool **arr1, bool **arr2, int m, int n) {
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
cout << arr1[i][j] * arr2[i][j];
cout << ' ';
}
cout << endl;
}
}
void subtractionMatr(bool **arr1, bool **arr2, bool **tempAr, int m, int n) {
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if ((arr1[i][j] == true) && (arr2[i][j] == false)) {
tempAr[i][j] = true;
}
else {
tempAr[i][j] = false;
}
cout << tempAr[i][j];
cout << ' ';
}
cout << endl;
}
}
void subtractionMatr(bool **arr1, bool **arr2, int m, int n) {
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if ((arr1[i][j] == true) && (arr2[i][j] == false)) {
cout<< true;
}
else {
cout<< false;
}
cout << ' ';
}
cout << endl;
}
}
bool** setMemory(int m,int n) {
bool** ar;
ar = new bool*[m];
for (int i = 0; i < n; i++) {
ar[i] = new bool[n];
}
return ar;
}
void inputElements(bool **bar,int m,int n) {
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
cin >> bar[i][j];
}
}
}
Код относящийся к посту ниже
+1
int main()
{
//Все функции в посте выше
int m,n;
bool **ar1;
bool **ar2,**ar3;
bool **tar;
bool **temp;
setlocale(LC_ALL, "RUS");
system("color F0");
cout << "\tЗАДАНИЕ 1" << endl;
cout << "Требуется доказать что (A*B)^-1=(B^-1)*(A^-1)" << endl;
cout << "Введите размерность матриц" << endl;
cin >> m;
cin >> n;
ar1 = setMemory(m, n);
ar2 = setMemory(m, n);
ar3 = setMemory(m, n);
tar = setMemory(m, n);
temp = setMemory(m, n);
cout << "Введите элементы матрицы А" << endl;
inputElements(ar1, m, n);
cout << "Введите элементы матрицы В" << endl;
inputElements(ar2, m, n);
cout << "Введите элементы матрицы C" << endl;
inputElements(ar3, m, n);
cout << "Cначала найдём (A*B)^-1" << endl;
cout << "A*B:" << endl;
multiple(ar1, ar2,tar, m, n);
cout << "Обратная (A*B): " << endl;
printLine(m);
obr(tar, m, n);
printLine(m);
cout << "Теперь переёдём к правой части, найдём (B^-1)*(A^-1) " << endl;
obr(ar2,tar, m, n);
obr(ar1, temp, m, n);
printLine(m);
multiple(tar, temp, m, n);
printLine(m);
cout << endl;
cout << endl;
printLine(40);
cout << "\tЗадание 2 " << endl;
cout << "Доказать что (А\\В)\\С=(А\\С)\\В " << endl;
cout << "А\\В :" << endl;
subtractionMatr(ar1, ar2, tar, m, n);
cout << "(А\\В)\\С :" << endl;
printLine(m);
subtractionMatr(tar, ar3, m, n);
printLine(m);
cout << "А\\C :" << endl;
subtractionMatr(ar1, ar3, tar, m, n);
cout << "(А\\C)\\B :" << endl;
printLine(m);
subtractionMatr(tar, ar2, m, n);
printLine(m);
system("pause");
return 0;
}
+2
#include "stdafx.h"
#include<iostream>
#include<fstream>
#include<string>
#include<map>
#include<iomanip>
using namespace std;
int main()
{
string word;
setlocale(LC_ALL, "Russian");
char s[80];
fstream inOut;
multimap<string, int>my;
multimap<string, int>::iterator it;
inOut.open("text.txt", ios::in);
for (int i = 1; i < 40; i++) {
inOut.getline(s, 256);
char* pch;
pch = strtok(s, " ,-:;");
while (pch != NULL) {
word = string(pch);
my.insert(pair <string, int>(pch, i));
//cout << pch <<'\t'<<i<< endl;
pch = strtok(NULL, " ,-:");
}
}
inOut.close();
//cout << s;
for (it = my.begin(); it != my.end(); it++) {
cout.width(25);
cout << (*it).first <<setw(5) << (*it).second << endl;
}
system("pause");
return 0;
}
Берёт из текста строки и сортирует в алфавитном порядке
0
enum BitNumber {
Bit0 = 0,
Bit1 = 1,
Bit2 = 2,
Bit3 = 3,
Bit4 = 4,
Bit5 = 5,
Bit6 = 6,
Bit7 = 7
};
Из крупного проекта, крупной конторы... Но это еще цветочки, ягодки дальше будут.
−1
#include <iostream>
using namespace std;
int main()
{
int a, b, c;
cin>>a>>b;
if(a==0&&b==0&&c==0)
cout<<"Black";
if(a==1&&b==0&&c==0)
cout<<"Red";
if(a==0&&b==1&&c==0)
cout<<"Green";
if(a==0&&b==0&&c==1)
cout<<"Blue";
if(a==1&&b==1&&c==0)
cout<<"Yellow";
if(a==1&&b==0&&c==1)
cout<<"Magenta";
if(a==0&&b==1&&c==1)
cout<<"Cyan";
if(a==1&&b==1&&c==1)
cout<<"White";
}
не спрашивайте, для чего
−1
Antony Polukhin
in
pro.cxx
Кстати, в EWG одобрили constexpr контейнеры http://open-std.org/JTC1/SC22/WG21/docs/papers/2018/p0784r1.html
так что есть все шансы к С++20 писать:
constexpr std::string result = foo();
t.me/ProCxx
/184343
Mar 16 at 10:47
Library pragmatism
Current implementations of standard libraries sometimes perform various raw storage operations through interfaces other than the standard allocator and allocator traits. That may make it difficult to make the associated components usable in constexpr components. Based on a cursory examination of current practices, we therefore propose to start only with the requirement that the container templates in the [containers] clause be usable in constexpr evaluation, when instantiated over literal types and the default allocator. In particular, this excludes std::string, std::variant, and various other allocating components. Again, it is our hope we will be able to extend support to more components in the future.
With regards to the default allocator and allocator traits implementation, the majority of the work is envisioned in the constexpr evaluator: It will recognize those specific components and implement their members directly (without necessarily regarding the library definition).
We might, however, consider decorating the class members with the constexpr keyword. Also, some implementations provide extra members in these class templates (such as libc++'s allocator_traits<A>::__construct_forward ) that perform non-constexpr-friendly operations (memcpy, in particular). Lifting such members to standard status would help interoperability between library and compiler implementations.
+4
bool MyClass::operator==(int elem){
if (list.isExist(elem)){
list.remove(elem);
return true; // Операция завершена успешно
}
return false; // Элемент elem не найден в списке
}
(C) https://www.linux.org.ru/forum/development/14063699?cid=14063991
Вырвано из контекста (треда), но считаю данная кучка должна лежать здесь.
−1
#include <iostream>
using namespace std;
struct MyType { MyType() { cout << __PRETTY_FUNCTION__ << endl; }};
MyType& MyType() { cout << __PRETTY_FUNCTION__ << endl; }
using MyType2 = struct MyType;
int main() {
// MyType t; <- error: expected ‘;’ before ‘t’
MyType();
struct MyType t;
struct MyType t1 = MyType();
struct MyType t2 = (struct MyType)::MyType();
struct MyType t3 = MyType2();
new(&t2) struct MyType();
return 0;
}
Крестоблядство по мотивам #23850.
https://ideone.com/XcK2hf.
Особенно меня порадовал каст на 11 строчке.