Ralph
So you just need to use comparator in std sort that compares values *a > *b. Why does it matter if you can or cannot copy?
In step 1 i had to create a reverse function. And now i have no create my nc_function that works on non copyable types
Ralph
I already tried to move then but in vain
Vlad
Vlad
Which shall swap pointer values between them
Ralph
I've used it in my reverse function
Ralph
I will send the template 2sec
Igor🇺🇦
I've used it in my reverse function
Is it possible to see some code? I'm confused
Ralph
Yes right away
Ralph
template <typename Iter> void reverse(Iter begin, Iter end) { while ((begin != end) && (begin != --end)) { std::iter_swap(begin++, end); } }
Ralph
This is my reverse function
Ralph
The question is to create nc_reverse that works with non copyable types
Igor🇺🇦
template <typename Iter> void reverse(Iter begin, Iter end) { while ((begin != end) && (begin != --end)) { std::iter_swap(begin++, end); } }
If have vector of pointers you just change values of pointers. You don't have to move original objects at all
Ralph
So i should use temporary variables?
Igor🇺🇦
If my understanding is correct the same method will work on vector with pointers. No modification is necessary.
Vlad
So i should use temporary variables?
I guess one could move in and out of the variable.
Ralph
std::unique_ptr<int> a{ new int(1) }, b{ new int(2) }, c{ new int{3} }; std::vector<std::unique_ptr<int>> v; /* add a,b and c to vector v */ /* TODO: Write your code here */ /* call reverse */ ::nc_reverse(v.begin(), v.end()); for (auto& p: v)std::cout << *p<<","; std::cout << "\n";
Ralph
This is the main.
Ralph
I thought the same, but why was i asked for it?
I mean it's not logic to ask twice, so i forgot about it
Ralph
Use std::swap lmao. It has specialization for the unique_ptr
Yeah you told me, and i've already done it in reverse. So you guys are telling me to keep it as it is?
Ralph
Oh, and i am trying to add the unique_ptr values to the vector using pushback, but is is saying build failed, without any error
Igor🇺🇦
Yeah you told me, and i've already done it in reverse. So you guys are telling me to keep it as it is?
First pointer after your original reverse will point to 3, second to 2 and so on. Is this what you want?
Anonymous
emplace_back
same thing in this case, it will call the deleted copy constructor
Ralph
emplace_back
v.emplace_back(a)?
Anonymous
Anonymous
v.emplace_back(a)?
v.emplace_back(std::move(a));
Vlad
v.emplace_back(a)?
v.emplace_back(std::make_unique<T> ());
Igor🇺🇦
Yes
So just leave your method as it is.
Ralph
It worked guyss. Thank you.
Ralph
But then why did he ask to implement a function like reverse
Ralph
I am still disturbed with that 😅
Anonymous
But then why did he ask to implement a function like reverse
probably didn't know that std::iter_swap existed
Ralph
I don't know
Sasuke
Do you have an idea why?
Coz unique_ptr are supposed to stay unique so no copy or assignment is allowed. You can only move
Ralph
Yes they've explained it to me thanks alot
Ralph
probably didn't know that std::iter_swap existed
So maybe i did wrong with the reverse function
Ralph
I shouldn't have used the swap method
Ralph
Otherwise why bother asking, you see?
Anonymous
🤷
Ralph
AS🌸
Hi, How can I write an arbitrary long piece of text ?
Henry
Hi can i have an idea how to find a 5x5 determinant
Anonymous
Hi can i have an idea how to find a 5x5 determinant
Same as how you find determinant for 3x3
Pavel
emplace_back
By the way, why emplace back and not push back (with std::move) in this case?
Vlad
Both work
Pavel
Just I think push back is a bit more clear here in a sense that we want to put this object to the container, not construct some object (maybe of a different type) in-place.
Anonymous
Anyone have oop basic concept slides
Aakash
Yes i saw this but this only work for classes not functions
You want to block a function access (non-class member) func() =delete something like this..??
Pavel
How can I use malloc here?!
Can you give more details about your problem?
AS🌸
Can you give more details about your problem?
I want write a program in C language by using malloc to accept a long input.
Pavel
I want write a program in C language by using malloc to accept a long input.
How big is input? Do you load text from a file or get it from console?
Igor🇺🇦
From console
Do you know fgets https://www.cplusplus.com/reference/cstdio/fgets/ ? Do you know realloc https://www.cplusplus.com/reference/cstdlib/realloc/? That should be enough for reading.
mohamed amine
In private pleez explain to me this line if ( (uint)*(byte *)(*(long *)(param_2 + 8) + 2) - (uint)*(byte *)(*(long *)(param_2 + 8) + 3) == 0x20) param_2 in the user input
Anonymous
Can you tell me why the error appears? #include <stdio.h> #include <locale.h> #include <stdlib.h> #include <locale.h> //int** osvob_memory(int n, int m, int ); void vvod(int, int, int); void vivod(int, int, int**); int** memory(int n, int m); void sort(int, int, int ); int main(void) { setlocale(LC_CTYPE, "RUSSIAN"); int n, m; int a; puts("Введите размер массива n [n][m]"); scanf_s("%d", &n); puts("Введите размер массива m [n][m]"); scanf_s("%d", &m); a = memory(n, m); vvod(n, m, a); vivod(n, m, a); sort(n, m, a); vivod(n, m, a); //osvob_memory(n, m, a); return 0; } int memory(int n, int m) { int pp; int i, j; pp = (int**)malloc(sizeof(int*) * n); for (i = 0; i < n; i++) { *(pp + i) = (int*)malloc(sizeof(int) * m); } return (pp); } void vvod(int n, int m, int** mm) { int i, j; printf("введите элементы в mm\n"); for (i = 0; i < n; i++) for (j = 0; j < m; j++) { printf("mas[%2d][%2d] = ", i, j); scanf_s("%d", (mm + i * m + j)); } } void vivod(int n, int m, int** mm) { int i, j; printf("\nВведенный массив: "); for (i = 0; i < n; i++) { printf("\n"); for (j = 0; j < m; j++) printf("%5d ", (*(mm + i * m + j))); } } void sort(int n, int m, int mm) { int i, j; int temp; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) if (*(*(mm + i) + j) > *(*(mm + i) + j + 1)) { temp = *(*(mm + i) + j); *(*(mm + i) + j) = *(*(mm + i) + j + 1); *(*(mm + i) + j + 1) = temp; } } } /*int osvob_memory(int n, int m, int mm) { int pp; pp = mm; int i, j; for (i = 0; i < n; i++) { for (j = 0; j < i; j++) free(*(mm + j)); free(mm); } return(mm); }*/
Anonymous
Can you tell me why the error appears? #include <stdio.h> #include <locale.h> #include <stdlib.h> #include <locale.h> //int** osvob_memory(int n, int m, int ); void vvod(int, int, int); void vivod(int, int, int**); int** memory(int n, int m); void sort(int, int, int ); int main(void) { setlocale(LC_CTYPE, "RUSSIAN"); int n, m; int a; puts("Введите размер массива n [n][m]"); scanf_s("%d", &n); puts("Введите размер массива m [n][m]"); scanf_s("%d", &m); a = memory(n, m); vvod(n, m, a); vivod(n, m, a); sort(n, m, a); vivod(n, m, a); //osvob_memory(n, m, a); return 0; } int memory(int n, int m) { int pp; int i, j; pp = (int**)malloc(sizeof(int*) * n); for (i = 0; i < n; i++) { *(pp + i) = (int*)malloc(sizeof(int) * m); } return (pp); } void vvod(int n, int m, int** mm) { int i, j; printf("введите элементы в mm\n"); for (i = 0; i < n; i++) for (j = 0; j < m; j++) { printf("mas[%2d][%2d] = ", i, j); scanf_s("%d", (mm + i * m + j)); } } void vivod(int n, int m, int** mm) { int i, j; printf("\nВведенный массив: "); for (i = 0; i < n; i++) { printf("\n"); for (j = 0; j < m; j++) printf("%5d ", (*(mm + i * m + j))); } } void sort(int n, int m, int mm) { int i, j; int temp; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) if (*(*(mm + i) + j) > *(*(mm + i) + j + 1)) { temp = *(*(mm + i) + j); *(*(mm + i) + j) = *(*(mm + i) + j + 1); *(*(mm + i) + j + 1) = temp; } } } /*int osvob_memory(int n, int m, int mm) { int pp; pp = mm; int i, j; for (i = 0; i < n; i++) { for (j = 0; j < i; j++) free(*(mm + j)); free(mm); } return(mm); }*/
/warn read the rules
Adams Scott
hello
Adams Scott
which command
ㅤㅤㅤㅤㅤ
which command
Maybe removing warning
Adams Scott
ah ok
Adams Scott
🥳🥳🥳
Beyond
just watch a crashcourse of c if you want a good summary of it. it would be probably kinda difficult to explain it in a telegram group
labyrinth
https://github.com/apache/incubator-brpc/blob/master/src/bthread/timer_thread.cpp I saw a usage that I have never seen before, class BAIDU_CACHELINE_ALIGNMENT TimerThread::Bucket, in which the BAIDU_CACHELINE_ALIGNMENT is beyond my knowledge