« first day (1896 days earlier)      last day (940 days later) » 

9:07 AM
@sehe so I ran into a problem with thread_pool - I put the server into the game plugin and the plugin blocks the main thread due to boost's initialization:

if (entry_event)
{
::WaitForSingleObject(entry_event, INFINITE);
::CloseHandle(entry_event);
}

because the game pre-loads the DLL before calling an externally defined function. I resolved this in the past by using io_context instead of thread_pool and calling io_context.run manually. Any ideas?
 
 
1 hour later…
10:30 AM
thanks jerry coffin
 
11:03 AM
Hi, I used the for loop but it did not work
oh no, I get it. The vector indexing begins from the right side lol not left
 
11:54 AM
Hi everyone!
I'm learning about templates.
I know about specialization with such a syntax:

template <typename T>
class Base{
public:
void print (T x);
};

template<>
class Base<int>{
public:
void print (int x);
};

and it looks clear: first empty parentheses describe adherence to template, and the second ones - specify certain type.
But now I have encountered implementation of remove_const
where there is the next syntax:

template< class T > struct remove_const { typedef T type; };
template< class T > struct remove_const<const T> { typedef T type; };
 
12:22 PM
Is this class partial specialization?
 
I'mma guess there's no answer for stuff like this 😅
https://chat.stackoverflow.com/transcript/message/53052909#53052909
 
@Lapys I'd start by looking at source myself
but be wary of designing around implementation details
 
12:37 PM
Lol. Guess there's not much of a clean front-end for stuff like that.
No worries, thankfully it's not a requirement 👍🏾
 
 
6 hours later…
6:16 PM
X f(){
    X x;
    X y;
    if(&x == &y){
        return x;
    }
    else
        return y;
}
Would it be possible to perform NRVO in this function ?
X is a simple class (only default constructor defined).
 
 
2 hours later…
7:58 PM
Hi guys I wrote a small code for rotating vectors however, I get a compiler error despite the fact that it compiles perfectly fine on visual studio but Codility gives an error not sure why
error:
You should not define the function 'main()'.
func.cpp: In function 'std::vector<int> solution(std::vector<int>&, int)':
func.cpp:9:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (size_t i{};i<K;++i)
~^~
func.cpp: In function 'int main()':
func.cpp:29:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (size_t j{};j<num;++j)
 
it tells you what it has an issue with?
Are you just asking why it's giving you an error for a warning? There's options like -Werror to make all or some warnings into errors
 
I don't really understand the error tho
 
"size_t" is unsigned and "int" is a signed type
this warning warns you when you compare integer values that can be negative with values of a type that can't be negative
 
I mean the part about not defining main() and std::vector<int>solution......
 
no idea what the main thing is, might be Codility specific, what do the instructions say?
 
8:04 PM
the instructions just say that it uses C++14 but not much else
 
8:22 PM
I'd assume Codility does that for you
the defining of main that is
 
ok thanks I'll try and sort that
'Codelity does that for you' . That is dumb(Codility) why not let write code from scratch?
Hi guys is std::shift_right and std::shift_left only available in C++20?
 
@Electrical_engineer_student because a lot of people don't' want to deal with the boilerplate?
@Electrical_engineer_student in what sense? because << and >> existed since C++98 and work on all integer types
ah ok... those are different
also technically yes, but you should rarely need them?
 
8:39 PM
I meant shift_right/left for vector but it seems that you need to use templates to make it work which I don't understand. I am trying to shift elements of a vector and make the first one the last one.
Like I want to make [3,8,9,7,6] to [6,3,8,9,7]
 
in place?
or not?
 
'by place' you mean changing the vector then yes
 
I mean if it's integers you can use the xor trick
but honestly just do it the obvious way
 
I don't know the obvious way. I used std::rotate but the problem is it does not work with smaller vector size
code:
std::rotate(A.begin(), (A.begin() + 4), A.end());
so if the vector size is less than 4, then it gives wrong answer
 
well the obvious way is reverse iterators and std::swap
basically it's a version of insertion sort... just without the sorting
it's basically O(2N) IIRC
 
8:45 PM
I did this and works well
what do you think?
std::rotate(A.begin(), (A.begin() + size(A)-1), A.end());// A is the vector
(Codility uses namespace std not me)
 
9:32 PM
Is there a way we can actually improve this question. It's sitting at -1 (by me) but I think it could have been much better but I can't think of how: stackoverflow.com/q/69185081/14768
 
don't let it bother you, seems fine to me
 
10:17 PM
Hi how can I make my code faster if I am trying to find an unpaired element in a large vector ? code snippet
#include<iostream>
#include<vector>
#include<algorithm>

int solution(vector<int> &A) {

int unpaired{};

for (size_t i{};i<A.size();++i)
{
if ((std::count(A.begin(), A.end(), A[i])) <2)
{
unpaired= A[i];
}

}
return unpaired;
}
 

« first day (1896 days earlier)      last day (940 days later) »