- 1
https://discord.gg/F7AdMAHAZq
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
Всего: 61
−2
https://discord.gg/F7AdMAHAZq
залетайте, я создал.
0
#include <iostream>
#include <string_view>
#include <source_location>
void log(const std::string_view message,
const std::source_location location =
std::source_location::current())
{
std::cout << "file: "
<< location.file_name() << "("
<< location.line() << ":"
<< location.column() << ") `"
<< location.function_name() << "`: "
<< message << '\n';
}
template <typename T> void fun(T x)
{
log(x);
}
int main(int, char*[])
{
log("Hello world!");
fun("Hello C++20!");
}
file: main.cpp(23:8) `int main(int, char**)`: Hello world!
file: main.cpp(18:8) `void fun(T) [with T = const char*]`: Hello C++20!
Previously, functions that desire to obtain this information about the call site (for logging, testing, or debugging purposes) must use macros so that predefined macros like __LINE__ and __FILE__ are expanded in the context of the caller. The source_location class provides a better alternative.
0
#include <iostream>
#include <vector>
#include <thread>
int f()
{
static int i = 0;
synchronized { // begin synchronized block
std::cout << i << " -> ";
++i; // each call to f() obtains a unique value of i
std::cout << i << '\n';
return i; // end synchronized block
}
}
int main()
{
std::vector<std::thread> v(10);
for(auto& t: v)
t = std::thread([]{ for(int n = 0; n < 10; ++n) f(); });
for(auto& t: v)
t.join();
}
0 -> 1
1 -> 2
2 -> 3
...
99 -> 100
https://en.cppreference.com/w/cpp/language/transactional_memory
−1
#include "property.hpp"
class person {
public:
person() = default;
~person() = default;
SETTER_PRIM(int, id);
SETTER_FLAG(bool, merried);
SETTER_ENUM(human, type);
SETTER_PTR(int, next);
SETTER_ARR(std::string, address, 3);
SETTER_OBJ_LR(std::string, name);
SETTER_OBJ_CLR(std::string, name);
SETTER_OBJ_RR(std::string, name);
GETTER_PRIM(int, id);
GETTER_FLAG(bool, merried);
GETTER_ENUM(human, type);
GETTER_OBJ_LR(std::string, name);
GETTER_OBJ_CLR(std::string, name);
GETTER_PTR(int, next);
GETTER_ARR(std::string, address);
private:
int id;
human type;
std::string name;
std::string address[5];
bool merried;
int* next;
};
https://habr.com/ru/post/459212/
0
template<typename Event>
void bindEvent(auto function)
{
connectionGuards.emplace_back(
std::make_unique<event::EventConnectionGuard<Event>>(
std::forward(event::emitter().on<Event>(boost::bind(
boost::mem_fn(function), static_cast<T*>(this), _1))
)
)
);
}
0
void remove_spaces(string data)
{ int i=0,j=0;
while(i<data.length())
{
if (isalpha(data[i]))
{
data[i]=data[i];
i++;
}
else
{
data.erase(i,1);}
}
cout<<data;
}
0
auto&& rv = elements | std::ranges::views::values | std::ranges::views::transform([](auto&& a) -> auto
{
StatisticsElementMultiple n = std::move(a);
n.nanosec /= n.count;
return n;
});
std::vector<StatisticsElementMultiple> el(std::begin(rv), std::end(rv));
std::ranges::sort(el, [](auto&& a, auto&& b) -> bool {return a.nanosec > b.nanosec; });
for(auto&& [nanosec, name, prefixes, count] : el)
{
printf("%-10d %04X %12s %6d\n", count, prefixes, name.c_str(), nanosec);
}
0
Бесконечный оффтоп имени kcalbа #1
K C A L B K C A L B
C C C C
A + A +
L + L +
B K C A L B K C A L B
K C K C
C A C A
A L A L
L B L B
K C A L K K C A L B K
C C C C
+ A + A
+ L + L
K C A L B K C A L B
0
.set XSIZE 96h
.set YSIZE 68h
.org {11h * 2h}
dw @vbi
.org 80h
.include "stdvideo.inc"
process:
mov %cl YSIZE
.loopy:
mov %ch XSIZE
.loopx:
call @processCell
loop %ch @.loopx
loop %cl @.loopy
ret
processCell:
mov %d 0h
mov %bl 3h
.loopy:
mov %bh 3h
.loopx:
mov %e %c
add %e %b
sub %e 0202h
cmp %e %c
ce jmp @.xskip
push %e
mov %bp %sp
call @index2rel
pop %e
cmpb [%e + @data] 0h
cg inc %d
.xskip:
loop %bh @.loopx
loop %bl @.loopy
push %c
mov %bp %sp
call @index2rel
pop %e
mov %al [%e + @data]
movb [%e + @ndata] 0h
cmp %al 0h
cz jmp @.dead
cmp %d 2h
cl ret
cmp %d 3h
cg ret
movb [%e + @ndata] 1h
ret
.dead:
cmp %d 3h
ce movb [%e + @ndata] 1h
ret
fill:
mov %c {XSIZE * YSIZE}
.loop:
mov %b %c
mod %b 100h
div %b 8h
add %b 80h
mov %al [%b]
mov %b %c
mod %b 8h
mov %e 1h
shl %e %b
and %al %el
cnz movb [%c + @data] 1h
loop %c @.loop
ret
render:
call @clsm1
mov %cl YSIZE
.loopy:
mov %ch XSIZE
.loopx:
push %c
mov %bp %sp
call @index2rel
pop %e
cmpb [%e + @data] 1h
cge push %c
cge call @setpixelm1
cge pop
loop %ch @.loopx
loop %cl @.loopy
ret
vbi:
cli
call @render
call @process
mov %c {XSIZE * YSIZE}
.loop:
movb [%c + @data] [%c + @ndata]
loop %c @.loop
rei
T1:
.org {3AAAh + @T1}
data:
.org {XSIZE * YSIZE + @data}
ndata:
https://pastebin.com/6gm30JWR
https://imgur.com/a/uSzbrgZ
игра конвея теперь и на pvc-16!
0
.org 80h
src: db "++++++++++[>+++++++>++++++++++>+++<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+."
table:
db 0h db 3Eh dw @i1
db 0h db 3Ch dw @i2
db 0h db 2Bh dw @i3
db 0h db 2Dh dw @i4
db 0h db 5Dh dw @i5
db 0h db 2Eh dw @i6
db 0h db 5Bh dw @i7
start: ; %a iptr %b dptr ;
.loop:
mov %cl [%a + @src]
cmp %cl 0h
je @.loop.break
mov %si 0h
.tloop:
mov %ch [4h * %si + {@table + 1h}]
cmp %cl %ch
jne @.tloop.continue
push @.tloop.break
mov %ip [4h * %si + {@table + 2h}]
.tloop.continue:
inc %si
cmp %si 8h
jl @.tloop
.tloop.break:
inc %a
jmp @.loop
.loop.break:
int 0h
i1: ; > ;
inc %b ret
i2: ; < ;
dec %b ret
i3: ; + ;
push %el
mov %el [%b + @data]
inc %el
mov [%b + @data] %el
pop %el
ret
i4: ; - ;
push %el
mov %el [%b + @data]
dec %el
mov [%b + @data] %el
pop %el
ret
i5: ; ] ;
push %c
mov %cl [%b + @data]
cmp %cl 0h
je @.loop.break
mov %c 0h
dec %a
.loop:
cmpb [%a + @src] 5Dh ; ']' ;
jne @.loop.1
inc %c
.loop.1:
cmpb [%a + @src] 5Bh ; '[' ;
jne @.loop.2
cmp %c 0h
jz @.loop.break
dec %c
.loop.2:
loop %a @.loop
.loop.break:
pop %c
ret
i6: ; . ;
push %cl
outb E9h [%b + @data]
.wait:
inb %cl E9h
cmp %cl 0h
jne @.wait
pop %cl
ret
i7: ; [ ;
push %c
mov %c [%b + @data]
cmp %c 0h
jne @.loop.break
mov %c 0h
.loop:
cmpb [%a + @src] 5Bh ; '[' ;
jne @.loop.1
inc %c
.loop.1:
cmpb [%a + @src] 5Dh ; ']' ;
jne @.loop.2
cmp %c 0h
jz @.loop.break
dec %c
.loop.2:
inc %a
jmp @.loop
.loop.break: pop %c ret
Hello World!