« first day (1563 days earlier)      last day (1292 days later) » 

3:02 AM
Hi, are all below the same?
int a = (i & 0xXX) >> x
int a = i & 0xXX >> x
int a =i & (0xXX >> x)
 
 
1 hour later…
4:24 AM
Hmm... precedence?
 
 
2 hours later…
6:53 AM
Other than CGI are there any options for putting a program written in C++ on a website, or at least connecting it's input/output?
 
 
1 hour later…
Ron
8:21 AM
Are calls to pure virtual functions UB? If my abstract class also has a non virtual member that does doPureVirtual();?
 
 
2 hours later…
9:56 AM
if you have an array of profits with associated costs, (pi,ci), given a fixed amount to spend, how do you maximise profits?
 
 
1 hour later…
11:18 AM
@northerner not sure what you mean, but for ages the login provider for MS was implemented in C++ for CPU usage reasons
@Ron calls to nullptr are UB yes
 
 
5 hours later…
4:45 PM
Hi, I would be happy if someone could help me with an issue I have in C++. Let say I have two vectors (or arrays) and I would like to compare the two element-wise and replace the elements of one vector if a certain condition (involving both vectors) is true. For instance lets consider
std::array<int, 10> s{5, 7, 4, 2, 8, 6, 1, 9, 0, 3};
std::array<int, 10> l{0, 7, 4, 2, 0, 6, 1, 9, 0, 3};
and now I would like to get as an output {5, 1, 1, 1, 8, 1, 1, 1, 1, 1}, i.e. replacing all instances where l[i]=s[i] with 1. What would be the best way to do this?
I tried working with replace_if, i.e.
std::replace_if(s.begin(), s.end(), [](const int a){return a==0;}, 1);
for (int a : s) {
    std::cout << a << " ";
}
std::cout << '\n';
that replaces all elements with 1 if the element is 0 in s, but I cant really figure out how to use the other array in the replace_if method, as I do not have access to the index of the iteration, right?
Any help appreciated!
 
I think the binary version of std::transform is what you could use
or just make a loop that advances both iterators
 
@PeterT Thanks, will look into std::transform
mhh not sure how this can help. As far as I understand std::transform (foo.begin(), foo.end(), bar.begin(), foo.begin(), std::plus<int>());
will just add the elements of bar and foo elementwise
but how can I make a comparison?
 
5:06 PM
std::array<int, 10> s{5, 7, 4, 2, 8, 6, 1, 9, 0, 3};
std::array<int, 10> l{0, 7, 4, 2, 0, 6, 1, 9, 0, 3};

std::transform(l.begin(),l.end(),s.begin(), s.begin(), [](const auto& a, auto& b){
    if(b==a)
      return 1;
    else
     return b;
    });
 
right, I just figured it out, thanks!!!
 

« first day (1563 days earlier)      last day (1292 days later) »