« first day (1603 days earlier)      last day (1253 days later) » 

Tom
8:33 AM
Hi all!
If mArray is az int * and mSize is an std::size_t, then in case of

mArray = mSize ? new int[mSize] : nullptr;

what is the condition? m_Size indicates the size of the array. If it is 0, then it returns false and in every other cases it returns true. Am I right? It seems a bit strange, as I can give negative number to std::size_t and in this case it also gives true.
 
nwp
8:44 AM
@Tom std::size_t is unsigned, it cannot be negative.
You should attempt to set warning flags so your compiler tells you when you try to assign a negative number to an unsigned data type.
 
user12698128
9:14 AM
hi, has anyone programmed with asio4all? Is it possible that I don't find complete documentation to use this library for the purpose of playing low latency audio? From what I read on the net, it is one of the most popular libraries used also at a professional level in recording studios due to the low latency, I thought I would find C ++ code in tons and instead little or nothing.
 
10:54 AM
How to return an std::optional reference?
 
you don't
I mean you could try with std::ref, but it's just not a good idea the way std::optional works
 
I have a class that stores a bunch of objects. I want to return the object from a find method. These objects are not cheap to copy.
 
nwp
Consider using a pointer.
 
yeah, as jank as that may seem, I've mostly had to resort to that too
 
hi
:1 hello
@Yashas how ?
 
11:01 AM
@MorganCodes ?
 
 
3 hours later…
2:20 PM
@Yashas Do you want to return an std::optional containing a reference, or do you want to return a reference to and std::optional?
 
2:41 PM
@FrançoisAndrieux std::optional<T&>
 
@Yashas In that case other comments are right. You cannot have an std::optional which contains a reference (references are not objects). You can try std::optional<std::reference_wrapper<T>> which would be similar, but not exactly an std::optional of a reference.
 
I was about to say that boost::optional does it, but I'm pretty sure it's UB there
 
3:21 PM
struct A { int x, y; };
struct B { struct A a; };
struct A a = {.y = 1, .x = 2}; // valid C, invalid C++ (out of order)
int arr[3] = {[1] = 5};        // valid C, invalid C++ (array)
struct B b = {.a.x = 0};       // valid C, invalid C++ (nested)
struct A a = {.x = 1, 2};      // valid C, invalid C++ (mixed)
any ideea why this is invalid in C++ ? is there any wrokaround?
 
nwp
It's invalid because the committee hasn't gotten around to specify that. I expect them to eventually do that.
It's a little more tricky in C++ due to constructors and destructors. For example in struct A a = {.y = 1, .x = 2};, should x or y be constructed first? Both answers are bad and unexpected in some way which is why they require the order to be correct for now.
 
Yeah, I think they mostly added the limited support for it, because the way they support it, it's mostly some added syntax for list initialization
 
dpaste.org/3yr7 anyone got any clues for me? the dp is hard to set up, greedy didnt work
 
nwp
MSVC is wrong to accept this, right?
 
they still don't fully support two-phase lookup?
 
nwp
3:28 PM
I'm not sure it's the same issue as that.
 
/permissive- also gets you the error in msvc
 
nwp
That's good at least. I should yell at someone to change flags.
That doesn't actually seem to be the case.
But they do have basically the same example in the explanation of the flag.
@Trajan To me it looks like the answer is 0. If you're lucky you already happen to be at position x and don't need to jump at all. That's probably not the intended answer, but it seems to be valid and minimal for the question as stated.
 
3:43 PM
@nwp no you start at 0 and need to an x>0
you have to make a jump
 
nwp
It says you are at position y which may be negative. But it doesn't have to be.
 
0 -> -1 ->1 -> 4
 
nwp
Ah, the y is not the starting position, it's just an example to explain how jumping works. I see.
 
i tried greedy (ie going forward 1+2+3 steps then minusing 1) but that didnt work for the example above
 
nwp
Why are you writing an algorithm?
 
3:46 PM
its a fun question, dont worry its think its too difficult
 
nwp
With the updated understanding the answer is 1 jump. 0->1. x happens to be 1 (since it asks for the minimum number we can wish things).
 
your not reading it very well :)
 
nwp
Or do they ask for the minimum number of jumps for arbitrary x?
 
nwp
Dunnow, I think the question is not well-written.
@Trajan That is indeed critical information you left out :P
 
3:49 PM
sorry
 
nwp
Dynamic programming should work though.
 
@PeterT they do but only with /permissive- on
 
setting it up is grim
 
nwp
int min_jumps(int x, int y, int k) {
    if (x == y) {
        return 0;
    }
    return std::min(min_jumps(x, y + k, k + 1), min_jumps(x, y - 1, k + 1)) + 1;
}
Then you add the map to memoize solutions and you might be good.
Maybe add a bit of A* too so that you don't go down a branch without a solution forever.
 
wouldn't it be better for memoization to just feed in the difference between x and y, instead of the two values
not that you'd get any benefit for one single search, right? Only if you have multiple values for x/y to check
 
3:56 PM
@nwp nothing like a simple bit of A*!
 
nwp
@Trajan Just make a list of k-depth branches to check. And it checks it by filling the list of k+1-depth branches to check and finishes with the k list before moving on to the k+1 list.
Though that does make the number of elements in the current branches list grow exponentially.
You can cut all branches where y > x + 1000 - k. Or something similar. That should make the lists go back to basically linear. Never mind, you can't.
 
omg!
so clever
 
nwp
I think you need a better A* than just looking at the depth. The heuristic could be y > x ? y - x : (x - y) / k.
 
@nwp this isnt going to work, how does it count the steps
 
nwp
The function returns the minimum number of steps.
 
4:10 PM
ive seen my mistake
not sure about your heuristic
but am i getting a max recursion depth error
 
nwp
There are 2 cases for the heuristic:
1: You are past the x already, meaning y > x, meaning you need at least y - x jumps to get there.
2: You are before x and need roughly (x - y) / k jumps, because you jump k far.
The increase in k is ignored, but probably doesn't matter for the heuristic.
 
i cant how to put it into the function though
i cant see where to put it in the function so that it can catch cases much further down the recursion callstack
 
nwp
You use a std::priority_queue and the heuristic calculates the priority. I don't think you need recursion anymore. It becomes a loop where you pop the most promising path, calculate 2 new paths, put them in the queue and continue the loop.
 
do you mean more like a bfs with a priority queue instead of a queue?
 
nwp
I think that's equivalent, yes.
@Trajan I think that's pretty much the definition of A*.
 
4:19 PM
ah ok lol
have you grinded codeforces/topcoder before? @nwp
you have top knowledge
 
nwp
I haven't. I don't think I'd be good at it and it feels bad to write throwaway programs. I prefer working on my CYOA engine.
 
im surprised you would get that algorithmic knowledge from that
 
nwp
I also studied CS, so ... I guess I'm glad it wasn't a complete waste.
 
 
6 hours later…
9:56 PM
Anyone online here have any experience with __m256i?
 
@StevenCellist like simd intrinsics?
sure, I've used them
 
Awesome. Do you happen to know a possibility to work from the last bit to the first? Like, if you shift left in the first char/int/whateverdatatype, you go on to the second, then to the third etc. But I want to find a way in which you can start in the last bit, and shifting left just shifts towards the first bit
 
you want to swizzle the elements?
or just shift out one element after the other
 
It's quite hard to explain. Say we use a 256 bit, split into 32 chars. We set the first char to value 1, thus it contains 00000001. Then, when we shift left 8 times, the first char becomes 0 again, but the second! char becomes 00000001. That's not what I want
I want to set the last char to 1, thus being 00000001, but after shifting left 8 times, I want the for-last! element to become 00000001. Thus, this effectively becomes a 256-bit long sequence through which I can shift left unbothered
 
10:11 PM
0000 0001 0000 0000 0000 0000 0000 0000 when shifted left by 8, you want it to become 0000 0000 0000 0000 0000 0000 0000 0001 ?
 
0000 0000 0000 0000 0000 0001 0000 0000 when shifted left by 8, should become
0000 0000 0000 0001 0000 0000 0000 0000 whereas by default, it becomes
0000 0000 0000 0000 0000 0000 0000 0001
And since this sequence can become quite long and random, I don't really want to re-assign values to each part, I wish to be able to shift left unbothered by those 'backward' jumps
Ideally this also works this way when shifting right, but that's secondary
 
I don't know if there's anything for all 256 bits, AVX2 has it for treating it as a pair of 128 bit numbers
 
Not quite it yet, but doubles the performance over 64 bit already. Do you know which function that is?
 
_mm256_bslli_epi128 is shifting left I think?
 
Shifts in bytes tho :(
 
10:20 PM
but like I said, it's only available with AVX2, so if you're stuck with AVX1 then no dice
 
I have AVX2
 
oh yeah, I guess so
 

« first day (1603 days earlier)      last day (1253 days later) »