« first day (1928 days earlier)      last day (916 days later) » 

1:34 AM
How do you convert a traditional nested for loop into something more functional? ex:

for(int i = 0; i < vec.size(); ++i)
for(int j = i + 1; j < vec.size(); ++j)
valueFromMath = doMathStuff(vec.at(i), vec.at(j));

I've been trying to figure out how to do something like this with std::ranges but I am not sure how to pass two arguments into a function with just one vector passed in.
Sorry, I can't figure out how to format it into nicer looking code.
 
 
4 hours later…
5:41 AM
@nwp thanks man that makes sense. It was the part about nullptr returning a bool false I couldn't get my head around.
 
 
3 hours later…
8:24 AM
I couldn't link to the local glibc I installed recently
any help?
maybe due to old gcc I have on the remote server?!
 
@EnthusiastiC did you re-compile everything? What's the actual error
 
9:00 AM
@PeterT needless. That server lacks many dependencies
and If I have to do I would create whole new env that ships with most recent popular programs and dependencies and that's pain in my opinion
 
yeah, cross-building for older glibc versions sucks hard. We're currently just doing that by using some docker images to compile things in. Because everything else is so much more involved and inconvenient
And glibc stuff is mostly forward compatible in my experience
 
I surrender. I don't have root priv. nor cloning is possible, nor dependencies are up to the minimal required
almost useless os in my opinion
 
why are you even trying to get stuff done on a server with such limited permissions
 
yeah! it's my supervisor who get me involved in this server in case of my primary server shutdown
 
nwp
9:15 AM
Maybe it's easier to just develop elsewhere and copy binaries.
 
@nwp did you mean by copying the binaries from my local linux system to this server I would get these programs to work such as glibc and gcc?
 
nwp
No, I meant you should compile locally and copy the binaries to the server. You probably shouldn't have gcc on the server at all.
 
I wished to run vs remote server
which requires glibc which requiers gcc which requires ....
glibc doesn't require gcc in principle but using third party tools, gcc is essential
(third party tools to avoid root usage)
 
You still haven't told us the "why" though. Like for faster compiling? for debugging on the target environment?
 
@PeterT I'm not sure if I understand your question. I wanted to update glibc to get VS code remote working just for fast coding as obviously known.
 
nwp
9:25 AM
It's not obvious why you involve the server when fast coding is your goal.
And maybe this is your chance to get into TDD so you don't need the debugger anymore.
 
I use the server to perform large calculations VS remote is for flexibility purpose
@nwp what is TDD anyway?
 
nwp
Test-driven development (TDD) is a software development process relying on software requirements being converted to test cases before software is fully developed, and tracking all software development by repeatedly testing the software against all test cases. This is as opposed to software being developed first and test cases created later. Software engineer Kent Beck, who is credited with having developed or "rediscovered" the technique, stated in 2003 that TDD encourages simple designs and inspires confidence.Test-driven development is related to the test-first programming concepts of extreme...
 
how to get into that?
 
nwp
Read books or watch videos on it.
 
hopefully, not beyond my skills
 
nwp
9:31 AM
I was half joking. I wouldn't actually recommend it.
But it doesn't require any special skills. All you have to do is write a test that checks if what you want done is done, watch it fail, and use minimal effort to make the test pass. Usually that involves writing wrong code. Then you improve your tests to force the implementation to be correct, at least correct in the sense that the tests pass.
You end up with very testable code, but it may or may not pain you to write wrong code.
And then there are things you cannot test properly because you don't know the correct solution or have nothing to test against. Usually GUIs are extremely difficult to test because we have great difficulty to define what a correct GUI is. But your server probably doesn't have GUI support anyway.
 
it is like a debugger?
 
nwp
No. It's not a tool. It's a software writing strategy somewhat similar to object oriented programming or contract-based design.
The main advantage is that you will end up with excessive tests that tell you if the program works as intended, tests you can use on the server, tests so good that if they pass there is no need for a debugger anymore.
 
I try to learn more about that TDD
 
nwp
The downside is that it's very not fun. Very tedious and boring. But opinions differ I guess. And that it isn't applicable to untestable things.
Usually you end up with a hybrid where you restrict it to useful tests and don't do the "minimum effort to make the test green" game.
 
 
7 hours later…
5:05 PM
Hi, how would you use enumerated data types in constructors? code snippet to follow:
#include<iostream>

enum col {RED, GREEN, BLUE};

class Cubes
{
public:

Cubes(uint32_t side1);// constructor with one argument

Cubes(unin32_t side1,col color);// constructor with two arguments

Cubes(const Cubes& Cubes);// copy constructor

~Cubes();// destructor

private:
uint32_t Side; // length of a side of the cube in millimetres
col Colour;
};
Cubes::Cubes(unint32_t side1)
{Side=side1}

Cubes::Cubes(unin32_t side1,col color)
:Side{side1},Colour{color}{}

Cubes::Cubes(const Cubes& Cubes)
:Side{Cubes.Side},Colour{Cubes.Colour}{}

Cubes::~Cubes(){};
error: expected constructor, destructor, or type conversion before ‘(’ token
I spent some time on stackoverflow but can't seem to find much info on this
error mainly comes at the definition of constructors
 
@Electrical_engineer_student you can't use {} as the initialization in an initializer list
you must use parens so it doesn't confuse with the body of the constructor
 
nwp
Huh? There should be no confusion possible.
 
so initialise like this:
Cubes::Cubes(unint32_t side1)
{Side=side1}
instead of the other one I did?
 
nwp
5:21 PM
@Electrical_engineer_student You have a ton of typos in the uint32_t and that particular line is missing a semicolon, but otherwise it compiles fine.
 
just realising how much typos there is, in my defence I had a long day[insert face palm emoji]
thanks guys
I will double/triple check all my code before posting here
 
5:44 PM
ok now I have a legit question(no typos this time)
so I defined my destructor so it outputs the object members like this:
Cubes::Cubes(const Cubes& Cubes)
:Side{Cubes.Side},Colour{Cubes.Colour}{}

Cubes::~Cubes()
{
std::cout<<"The color of this cube is "<<Cubes::Colour
<<" \nAnd the side length is "<<Cubes::Side<<".\n";
}
when I do this, I get an expected response:
int main()
{
// define objects of type Cubes
Cubes Cube1(10,GREEN);
//Cubes Cube2(2);
}
but when I uncomment the line 'Cubes Cube2(2)', I get a strange output
why is this happening? why is the destructor not getting called after each constructor is destroyed?
 
nwp
One issue is that the type and parameter are both named Cubes. Very confusing.
 
in the copy constructor?
 
nwp
Yup
@Electrical_engineer_student Probably because you never initialized Colour.
 
copy constructor is not even being called in the int main() I showed?
 
nwp
It isn't being called, but it is being compiled which is probably already an issue.
 
5:51 PM
I initialised Colour but that does nothing, the first line of int main() works well: 'Cubes Cube1{10,GREEN}' but its the when the second line is uncommented creates problems
@nwp ok lemme sort it
 
nwp
Well, try to be more specific about what problems you're encountering.
 
ok so I changed it, is this OKAY ?
Cubes::Cubes(const Cubes& cubic)
:Side{cubic.Side},Colour{cubic.Colour}{}
 
nwp
Sure
 
the problem is this:
int main()
{
// define objects of type Cubes
Cubes Cube1(10,GREEN);
Cubes Cube2(2);
the output it produces:
The color of this cube is 0
And the side length is 2.
The color of this cube is 1
And the side length is 10.
I don't understand why is the first length 2?
 
destruction need to happen in reverse order
otherwise you would mess up dependent objects
 
5:55 PM
ah..... so Cube2 gets destroyed first, then Cube1. Got it
@PeterT thanks man appreciate the help ! also thanks again to @nwp
 
struct A{int v =5};
struct B{A* a; ~B(){std::cout << a->v << std::endl;}};

int main(){
A a;
B b{&a};
}
what would this print if "A a" was destroyed first
 
I dunno because if a is destroyed then the '&a' would compute the hexadecimal address of something that doesn't exist right?
so this would be undefined behaviour if 'A a' is destroyed first?
ok so I know that if struct B is destroyed then it will print 5.
 
6:12 PM
I was just trying to illustrate why it's important that objects are destroyed in reverse order
 
@PeterT ok makes sense, but what would it print if A was destroyed first ?
 
it's a pointer into a destroyed object, undefined behavior what happens.
 
actually I said: ' &a would compute the hexadecimal address ' now I know that the ampersand is used because in struct B 'A* a' has this pointer
 
nwp
I think you can take the address of a destroyed object, not sure. But it's pretty useless. The dereferencing, however, is UB.
 
6:31 PM
@nwp AFAIK not directly, you can if it's in an allocated buffer. But then it's not technically an object at that time.
 
 
1 hour later…
7:47 PM
why does getline stop working when used more than once?
code snippet:
class Computers
{
public:
void ReadValues() // read values for all members from the user
{

std::cout << "Enter values for processor\n";
std::cin.getline(Processor, 20);
std::cout << "Enter values for memory and disk.\n";
std::cin >> Memory >> HardDisk;
}// char Processor[20]; declared in the class later on
so getline works the first time but after that it skips asking the value for processor.(I know I should use std::string but this is someone else's code so don't want to change it too much )
actually nvmd
its fixed by using 'std::cin.ignore();'
 

« first day (1928 days earlier)      last day (916 days later) »