-
−1
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
#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";
}
не спрашивайте, для чего
ramune,
18 Марта 2018
-
−1
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
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.
j123123,
16 Марта 2018
-
+4
- 1
- 2
- 3
- 4
- 5
- 6
- 7
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
Вырвано из контекста (треда), но считаю данная кучка должна лежать здесь.
Elvenfighter,
05 Марта 2018
-
−1
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
#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 строчке.
Bobik,
03 Марта 2018
-
+2
- 1
- 2
- 3
- 4
- 5
- 6
- 7
MyType(const CopyPastedFromSomewhere&) = delete;
MyType& operator=(const CopyPastedFromSomewhere&) = delete;
MyType& operator=(const MyType*) = delete;
// Winner?
MyType& MyType(const MyType&) = delete;
А что можно найти в вашей кодовой базе? К слову, выяснилось, что вариант
void operator=(const MyType&) = delete;
вполне себе допустим.
roman-kashitsyn,
02 Марта 2018
-
0
- 1
- 2
- 3
- 4
- 5
- 6
#include <xmmintrin.h>
void crasher() {
constexpr __m128 w = {1,2,3,4};
asm ("addps %[w], %[w]" : : [w] ""(w));
}
Крашим GCC
https://ideone.com/iIAN0i
Antervis,
28 Февраля 2018
-
0
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
class PriceCache {
public:
FlightStorage(const std::size_t count) {
for (std::size_t i = 0; i < count; ++i) {
flights.emplace_back(FlightCache::get(i));
prices.emplace_back(&flights.back(), Price::getFor(flights.back()));
}
}
private:
std::vector<Flight> flights;
std::vector<const Flight *, double> prices;
};
"случайные сегфолты при обращении к PriceCache::prices"
Elvenfighter,
28 Февраля 2018
-
0
- 1
return f() <= x->size() ? true:false;
Классика?
syoma,
20 Февраля 2018
-
−1
- 1
- 2
- 3
- 4
// Read option name (can contain spaces)
while (is >> token && token != "value")
- name += string(" ", name.empty() ? 0 : 1) + token;
+ name += (name.empty() ? "" : " ") + token;
terminate called after throwing an instance of 'std::length_error'
what(): basic_string::_M_create
Replacing string(" ", name.empty() ? 0 : 1) with (name.empty() ? "" : " ") and the same in the while() loop for value fixes the problem (for me).
Does anyone know if "string(" ", 0)" is invalid C++ ?
Кресты такие кресты.
3.14159265,
18 Февраля 2018
-
0
- 1
- 2
- 3
- 4
- 5
double x = 0, y;
while (x < 1) {
y = x;
x += rand(0, 1);
}
Задача на теорию вореации и кобенаторику.
rand - равномерное распределение
Нужно найти матожидание y. С пруфами.
3_dar,
07 Февраля 2018