#development

1 messages · Page 172 of 1

wheat mesa
#

That’s cheating

#

Write it by hand first

lyric mountain
#

I mean, you still have to write the logic yourself, antlr simply identifies and iterates the elements

wheat mesa
#

I don’t think antlr is used too much in many spots nowadays

#

It’s cool to learn how it works but I think it’s important to know how to write both a lexer and parser by hand

lyric mountain
#

antlr is surely used nowadays wdym

radiant kraken
#

just use an unsigned 32-bit integer mmLol

#

it'll save you for a couple more years

lyric mountain
#

stonks

magic sonnet
#

Tryna slide?!

sharp geyser
#

Honestly making a lexer and parser with my current knowledge would be ludicrous

#

I still yet to fully grasp language specific features like classes, pointers, references, and anything else beyond basic datatypes and rudamentary knowledge on functions (as I am pretty sure functions are not entirely like what I am used to in languages like js)

#

I am severely lacking

wheat mesa
#

Lexing is basically just a fancy word for “loop over characters to see if I recognize something”

#

And attaching metadata to each of those characters (line number, column number, if they are a keyword, etc)

sharp geyser
#

I mean yea it might not be hard, but I also am not confident to tackle something like that, nor do I know where to start. I understand it would give me valuable knowledge and a learning experience.

wheat mesa
#

Parsing is a bit more complex but for basic math expressions it’s quite simple

#

Fair

#

Well if you end up finishing that calculator thingy lmk if you want a little code review 😉

#

(Or if you need help with the “correct” approach)

sharp geyser
#

Honestly I am stuck on where to proceed so I dont see myself getting far right now.

wheat mesa
#

What are u stuck on

sharp geyser
#

I also have work in 18 minutes

wheat mesa
#

Oh

#

Rip

#

I work tomorrow, Friday, and Saturday 😭

sharp geyser
#

Called in early

#

I have Friday off

sharp geyser
#

Ophidian gave some helpful advice

#

but I don't really know how to actually implement something like what he suggested with C++

wheat mesa
#

Are you looking to be accurate for order of operations?

#

Or do you just want to evaluate sequentially

sharp geyser
#

For now I just want it to evaluate something

#

Correct or not kek

wheat mesa
#

Order of operations is the hardest thing to do in a calculator like this, but if you don’t care about order of operations then it should be pretty trivial

sharp geyser
#

I'd like to eventually implement following pemdas

wheat mesa
#

Pemdas is likely going to need a proper parser or something like the shunting yard algorithm to implement

#

Not too good of a way around it

sharp geyser
#

Yep

#

Which is why I want to build my knowledge with something simple first

lyric mountain
#

I can show u how I achieved my pemdas

#

with antlr tho

wheat mesa
#

Antlr is cheating if he wants to learn C++ with this project tho :c

lyric mountain
#

but the syntax is quite simple to understand

lyric mountain
sharp geyser
#

I'd rather stick to do it my own

lyric mountain
#

the matcher declaration, can help giving an idea on how to sequence your matches

#

not to use antlr or anything

#

after u have an image of the chain you're trying to build, u can focus on implementation

wheat mesa
#

If you want a good bit of practice you can make a RPN evaluator with a simple std::list and looping over characters

#

That way PEMDAS isn’t a giant barrier since there is no order of operations for RPN

#

2 2 3 + * is equal to 10 for example

#

3 + 2 = 5
5 * 2 = 10

sharp geyser
#

Never seen an eqaution like that

wheat mesa
#

It’s called reverse Polish notation

#

It can be trivially evaluated with a stack of operands and operators

sharp geyser
#

So basically all the numbers come first and the operators go after

#

and it evalutates whatever two numbers are closest to the first operators

#

then continues down the list?

wheat mesa
#

Basically
If you encounter a number, push it on to the operand stack
If you encounter a operator, pop 2 numbers from the operand stack and push the result back on to the operand stack

sharp geyser
#

Makes sense

#

I could do it that way

wheat mesa
#

It’s easy to implement but still lets you learn a bit before going into evaluating “normal” notation

sharp geyser
#

I will try and implement something of the sort after work

digital swan
#

bump 😁

magic sonnet
#

This is my code: https://haste.reversed.dev/p/lVW8XC.js
I get this error;
DiscordAPIError[50035]: Invalid Form Body
8[APPLICATION_COMMANDS_DUPLICATE_NAME]: Application command names must be unique

#

Why?

deft wolf
#

You already have a command with this name

magic sonnet
#

The command has 2 sub commands though in the same file.

deft wolf
#

But this most likely has nothing to do with this exact command. Check where exactly this error comes from, I assume it's when registering commands. If you have two of the same commands with the same name, change them to something else

lyric mountain
grim aspen
magic sonnet
grim aspen
#

lemme guess, there's a missing '}'

magic sonnet
#

I initially didn't think of adding a reminder list command until after

grim aspen
#

yeah you have a duplicate sub command

magic sonnet
#

The list one just doesn't register only the add sub command does

grim aspen
#

the problem is that you have a duplicate command somewhere in your index.js file

#

that's what it's saying

magic sonnet
#

Ahhhhh I found that

magic sonnet
#

It ended up being because I forgot to delete the old files from the my repo before making the new one.

deft wolf
#

Good job

#

Glad it worked

compact pier
#

Wherer should I store one time password? Should I use redis for that?

lyric mountain
#

wdym one-time password?

#

if you're going to use it once and never again, dont store it

compact pier
#

I mean like a email confirmation code

#

so I need to store the generated code somewhere to check it

lyric mountain
#

hm, I was going to say "you dont store those", but technically u do need to keep it for a while

#

you can keep it in memory for a while and then discard afterwards

compact pier
#

you think? it sounds like unefficient tho

lyric mountain
#

it's the other way around

#

you'll be storing what, 5 characters per verification request?

compact pier
#

yes

lyric mountain
#

a simple map/dictionary will do

compact pier
#

and user id

lyric mountain
#

with userid-code pairs

#

once the time elapses, or the user verifies successfully, u remove the entry

compact pier
#

do you think array will be better? like just userid-code

#

or it takes more memory

lyric mountain
#

there are expiring-map libs out there, redis has this too iirc

compact pier
#

okok

lyric mountain
#

maps are O(1) for key accesses

#

since you'll be retrieving the entry based on userid, it'll be the best option

compact pier
#

Ok understood, thank you

lyric mountain
#

yw

wraith merlin
#

I added my bot but its not showing up, i did it yesterday

sharp geyser
#

Its likely still in queue then

wraith merlin
#

Im also trying to get the token for my Topgg thing

deft wolf
#

You have to wait until they approve your bot

#

If your bot is accepted, you will find your token in the "webhook" tab when editing your bot

sharp geyser
#

@wheat mesa So here's my thought process on how to achieve this using reverse polish notations. I have 2 lists, one for operands, and the other for operators. Then I will evaluate that by taking the last two entry in the operands and the first in the operators and evaluating it then assigning it to a temp variable. Now if there are no operands left, then it stops evaluating and gives the final result.

wheat mesa
#

Yup that’s pretty much the algorithm

#

The only reason stacks are used is because it’s more efficient than vectors

#

(But if by list you mean std::list then that’s a linkedlist so it works as a stack for this impl)

wheat mesa
#

I mean it still works, it’s just a little more inefficient

radiant kraken
sharp geyser
#

@wheat mesa @radiant kraken @earnest phoenix

    std::string expression;

    std::cout << "What would you like to evaluate?\n";
    std::getline(std::cin, expression);

    std::vector<std::string> tokens;
    std::istringstream stream(expression);
    std::string token;

    std::vector<int> operands;
    std::vector<std::string> operators;

    while (stream >> token) {
        tokens.push_back(token);
    }

    char* endPtr;

    for(const std::string& token : tokens) {
        long operand = std::strtol(token.c_str(), &endPtr, 10);


        if (*endPtr == '\0') {
            operands.push_back(operand);
        } else {
            operators.push_back(token);
        }
    }

How do you like my code for parsing the input into ints. I don't think I can use strings for operators but for now idc.

radiant kraken
#

looks really good for a beginner

sharp geyser
#

I had to chatgpt to int part

radiant kraken
#

bru

#

why not use stackoverflow

sharp geyser
#

stackoverflow was not giving me proper answers

#

it was only giving int -> string not string -> int

radiant kraken
#

oh well

sharp geyser
#

I also don't really understand how strtol works

radiant kraken
#

it looks good enough

sharp geyser
#

I have a vague understanding on what it does

radiant kraken
sharp geyser
#

but no idea why I have to use a char pointer

sharp geyser
radiant kraken
sharp geyser
#

OH okay

#

so if endptr is not a nullptr it will set the value of endptr to the first character after the number

#

which is why I check for \0

#

to see if its successful

sharp geyser
#

So what exactly is a nullptr then

#

Cause reading on it I don't quite get it

#

I understand its better than using 0 or NULL

radiant kraken
#

it's the same thing

#

nullptr === NULL === (some_type *)0 === me

sharp geyser
#

so when is the appropriate time to use nullptr?

radiant kraken
#

in strtol?

sharp geyser
#

Should I use it there?

#

I figured it'd be good to not use it since I need to verify if the conversion was successful

#

and if it fails to convert something wont it error if nullptr is used?

radiant kraken
#

you pass in nullptr/NULL to the second argument (endptr) if you don't need to parse the next integers following the current one

sharp geyser
#

Ah

#

Gotcha

#

I was just wondering when its appropriate to use nullptr period

radiant kraken
#

it's only useful when you want this:

char a[] = "69";

long sixtynine = strtol(a, NULL, 10);
sharp geyser
#

no no

#

not talking about with strtol

#

Im just talking in general

radiant kraken
#

oooo

#

it's kind of like an optional/error type but for pointers

sharp geyser
#

I see

#

On another note

#

What would be the best way to get the last x elements of a vector

#

for example say I wanted the last 2

radiant kraken
#

this?

sharp geyser
#

I could do that

#

hm

#

I just need to use a loop of some kind so it always gets the last two if possible and keeps evaluating the expression until it reaches the end

#

I was thinking of using a while loop

radiant kraken
#

yup

sharp geyser
#

Wait

#

switch case statements only accept ints

sharp geyser
#

Because if it gets down to there only being operand left then it could cause errors or UB

sharp geyser
#
#include <iostream>
#include <string>
#include <vector>
#include <sstream>


int main() {
    std::string expression;

    std::cout << "What would you like to evaluate?\n";
    std::getline(std::cin, expression);

    std::vector<std::string> tokens;
    std::istringstream stream(expression);
    std::string token;

    std::vector<int> operands;
    std::vector<std::string> operators;

    while (stream >> token) {
        tokens.push_back(token);
    }

    char* endPtr;

    for(const std::string& token : tokens) {
        long operand = std::strtol(token.c_str(), &endPtr, 10);


        if (*endPtr == '\0') {
            operands.push_back(operand);
        } else {
            operators.push_back(token);
        }
    }

    int result = 0;

    for(int i = 0; i < operands.size(); i++) {
        int op = operands.back();

        if(operators.front() == "+") {
            result += op;
        } else if(operators.front() == "-") {
            result -= op;
        } else if(operators.front() == "*") {
            result *= op;
        } else if(operators.front() == "/") {
            result /= op;
        }
    }

    std::cout << result << std::endl;



//    std::copy(operands.begin(), operands.end(), std::ostream_iterator<int>(std::cout, " "));
//    std::copy(operators.begin(), operators.end(), std::ostream_iterator<std::string>(std::cout, " "));

    return 0;
}

in theory this seemed fine, in practice not so much

#

Then I remembered for the reverse polish notation to work, I need to take the last two numbers and not just the first one

#

😔

radiant kraken
sharp geyser
#

Honestly

#

I am just dumbfounnded on what to do

#

Cause I can easily get the last two, but on how to actually do the evaluations is beyond me

sharp geyser
#

Like I can get the last to operands

#

but on how to evaluate them based on the first operator I have no idea

#

I cant seem to figure it out

radiant kraken
#

but i dont really have the time to code it rn sdSadge

sharp geyser
#

You could explain it instead

radiant kraken
#

wait

#

something like this @sharp geyser

char * input = ...;
char * endptr = input;
bool first = true;
long last;

while (1) {
  long a = std::strtol(endptr, &endptr, 10);

  char Operator = get_next_operator(&endptr);

  if (first) {
    first = false;
    long b = std::strtol(endptr, &endptr, 10);

    last = execute(Operator, a, b);
  } else {
    last = execute(Operator, last, a);
  }

  if (*endptr == '\0') break;
}
// result is `last`
sharp geyser
#

I mean I didnt really want code

#

I was looking for more of a guidance

radiant kraken
#

its a bit hard to explain

sharp geyser
#

Also

#

I wasn't stuck on getting the last two I was stuck on actually how to execute it

sharp geyser
#

Because I dont see how I can execute the equation?

radiant kraken
#

hmmmm

#

wait why are you evaluating from the end

sharp geyser
#

its a reverse polish notation. I use push_back to add the operands to the vector

#

so I get the last 2 and take the first operator

radiant kraken
#

ooooo

#

god this is so confusing notlikekomi

sharp geyser
#

Basically it goes
2 2 3 + *
2 + 3 = 5
5 * 2 = 10

radiant kraken
#

hmmmmmmm

sharp geyser
#

Use of undeclared identifier 'evaluate'

radiant kraken
#

obviously it was a prototype

sharp geyser
#

clearly exists

sharp geyser
#

but I made my own evaluate function

#

but it is saying it no exist

#

Wait

#

do I have to put the function before the main function

#

is that how C++ work

radiant kraken
#

maybe something like this? ```
first = true
length = operands.size()

for i = 0; i < length; i++
b = operands.back()
operands.pop_back()
a = operands.back()
operands.pop_back()

operator = operators.front()
operators.pop_front()

operands.push_back(execute(operator, a, b))

result = operands.back()

sharp geyser
#

I never thought about just overwriting what the operands vector is

#

That is actually genuis

radiant kraken
#

i'm so sorry that it took me a while to understand your problem lmao

#

@earnest phoenix what do you think?

earnest phoenix
sharp geyser
#

Okay

#

that is bs

#

I did not try and share harmful content

radiant kraken
#

C++ is harmful

sharp geyser
#

@real rose fix automod

radiant kraken
#

to me at least

earnest phoenix
sharp geyser
#

uh oh spaghettio

earnest phoenix
radiant kraken
#

asdfasdjfijdsfishdfuhsdufhsdf

sharp geyser
#

I am using reverse polish notation

#

:D

sharp geyser
earnest phoenix
radiant kraken
#

what do u think of my pseudocode?

earnest phoenix
#

Why would you do that?

sharp geyser
#

uh oh

radiant kraken
#

to suffer ig

sharp geyser
#

In theory it sounded okay

radiant kraken
#

tho its really good for learning about stacks

sharp geyser
#

It made sense to me, probably not the best way to do it but hey

#

if it works it works

#

I wonder why its exiting tho

#

Apparently a seg fault or access violation

radiant kraken
#

yep

#

it's a segfault

sharp geyser
radiant kraken
#

could be a problem on how you're getting the operands and operators

#

or was it working before?

sharp geyser
#

I could do operands.back perfectly fine

#

I think its the for loop

earnest phoenix
#

It's not entirely horrendous, just very inefficient to handle actual compound equations and such, the proper way to handle the discovery of operands and their relative binary expressions is to peek through the characters in the token stream, and going by the rules of operator precedence, construct the structure of the equation from either the left or the right side

#

And if nothing fits in there, throw a syntax error

sharp geyser
#

Well yes

#

I understand that, but I thought it'd be more fun

radiant kraken
#

wait what's ur code

earnest phoenix
sharp geyser
#

Is it not this one?

earnest phoenix
#

Open C:\Program Files\LLVM\bin, what do you see?

sharp geyser
earnest phoenix
#

I can't read anything, the text is too pixelated

#

Is lldb.exe there?

sharp geyser
#

yes

earnest phoenix
#

Try running lldb --version in the console

sharp geyser
#

looks like I need python installed no?

earnest phoenix
#

Well there you go, you need to install Python since LLDB uses it

sharp geyser
#

I didn't know that

radiant kraken
sharp geyser
#

one sec

sharp geyser
earnest phoenix
#

Damn Hastebin has changed a lot

radiant kraken
#

hmmmm reinterpret_cast<const char *>(token)

#

this rings a red flag to me

#

wait

#

nvm

sharp geyser
#

Thats something the IDE did on its own actually

#

I didn't even do it

radiant kraken
#

before the for(int i = 0; i < operands.size(); i++) loop, what does std::cout << operands << '\n' << operators << std::endl; yield?

#

does it work as expected

sharp geyser
#

well you can't print vectors like that

radiant kraken
#

wait really?

#

damn

#

then print each element with a for loop

earnest phoenix
#

Did you install Python yet? mmLol

sharp geyser
#

Yes

#

and lldb still gives me shit

earnest phoenix
#

What does it say?

sharp geyser
#

Now then to answer null's question, same shit happens even before the for loop

sharp geyser
radiant kraken
sharp geyser
#

Its likely the casting to char *

#

thats the only thing I can think of that i've done differently

#

but strtol takes in a std::string or char* not char

radiant kraken
#

as i said before, maybe it's something wrong with this ```cpp
for(const char& token : tokens) {
long operand = std::strtol(reinterpret_cast<const char *>(token), &endPtr, 10);

#

i'm not really that big into C++, is there anything wrong with this? @earnest phoenix

sharp geyser
#

thats what I am thinking

radiant kraken
#

i'm more of a C dev than C++ onesieKEKW

sharp geyser
#

@earnest phoenix So I can't even install python 3.10 anymore its in a security release only stage

#

and the security release doesn't even have the python310.dll

radiant kraken
#

imo it's better to just try to solve the segfault ourselves without a debugger first

#

the problem is most likely on that for loop

sharp geyser
#

Its probably the casting

#

that can be the only thing I can think of

earnest phoenix
sharp geyser
#

Already have it open

sharp geyser
#

I did something that was probably worse and got it to work

earnest phoenix
sharp geyser
#

Now its a different error regarding calling back on a empty vector

radiant kraken
sharp geyser
# radiant kraken what was it?
    char myCharArray[2];
    myCharArray[0] = token;
    myCharArray[1] = '\0';

    for(const char& token : tokens) {
        long operand = std::strtol(myCharArray, &endPtr, 10);

mmLol

#

no idea what it does

#

but did it to see if it would fix the problem

earnest phoenix
radiant kraken
earnest phoenix
#

I'm not exactly sure why LLDB doesn't use the latest Python DLL, but eh

sharp geyser
#

I bet

radiant kraken
#

is the result as expected?

sharp geyser
#

I just don't know what it does

sharp geyser
#

new error

#

it aborts because back is called on an empty vector

radiant kraken
#

lmao

sharp geyser
#

probably the operators vector

earnest phoenix
#

Note that you were casting a reference to a pointer, this is not entirely valid

sharp geyser
#

As there is 3 in the operands 2 in the operators

#

so its trying to pull a 3rd from the operators when it doesn't exist

radiant kraken
#

not really sure what this does```cpp
std::vector<char> tokens;
std::istringstream stream(expression);

while (stream >> token) {
    tokens.push_back(token);
}
#

what is tokens?

#

does it just split by whitespace

sharp geyser
#

yea

radiant kraken
#

or

sharp geyser
#

it splits it based on whitespace iirc

radiant kraken
#

is it just the characters for the string

sharp geyser
#

tokens is just the operands and operators

#

it splits based on whitespace

#

and then I split them off into their own vectors

radiant kraken
#

so "2 3 +" -> '2', '3', '+'

sharp geyser
#

yep

#

issue is

radiant kraken
#

i see where that would work, not sure when you do 23 59 + tho

sharp geyser
#

I am not accounting for the fact that there will be more operands than operators

earnest phoenix
radiant kraken
#

i mean

#

it's to a std::vector<char>

#

so wouldn't it be '2', '3', '5', '9', '+'?

earnest phoenix
#

It's undefined behavior

radiant kraken
#

bruh nice

#

what if you do std::vector<std::string>?

earnest phoenix
#

That's the proper way

sharp geyser
#

oh wait what

#

why is tokens set to char

radiant kraken
#

there we go

sharp geyser
#

Ah wait I realize now

earnest phoenix
#

I think you should prioritize setting up the debugger, it'll help you fix them much faster

radiant kraken
#

nah

sharp geyser
radiant kraken
#

it'll be better if we can get misty to make his calc app working

earnest phoenix
#

Funnily enough this is what it showed for the initial error, note the arguments

sharp geyser
#

Okay

#

changing tokens to std::string caused a lot of problems

#

and my brain is having issue solving em

earnest phoenix
#

Just lldb path/to/executable, and r (shortcut to process launch)

radiant kraken
#
for(const std::string& token : tokens) {
        long operand = std::strtol(token.c_str(), &endPtr, 10);


        if (*endPtr == '\0') {
            operands.push_back(operand);
        } else {
            operators.push_back(token);
        }
    }
``` try this
sharp geyser
#

yea that is what I was doing

#

but operators is a char vector

#

because I use a switch/case in the evaluate function to make my life easier when doing the math

radiant kraken
sharp geyser
#

yep

#

brain officially hurty

#

C++ is so strict with everything js would just be like "ok yep makes sense"

earnest phoenix
#

I'm a bit lost, can you show the current code and the behavior?

sharp geyser
radiant kraken
sharp geyser
#

its having issues cause at L 59 operators is a char vector and I am trying to push a std::string

#

I am using chars for the operators because it makes no sense imo for it to be a std::string and it allows me to use a switch/case to do math evaluations easier

#

tho that might just be my brain being wonky

radiant kraken
#

also

#

isnt it like 3 am for u

sharp geyser
#

1:11am

#

I usually sleep at 2am and wake up at 10am

#

perks of graduating

#

and having a job that is a closing shift

radiant kraken
#

sleep smh

sharp geyser
#

Not yet

#

not tired

#

also gotta eat food

earnest phoenix
#

It's a single char, nothing else

sharp geyser
#

2 2 3 + * = 7
not sure how it got 7

#

unless its

#

2 * 2 = 4 + 3 = 7

earnest phoenix
#

Those equations walterstare

sharp geyser
#

Wait no

#

its doing 3 + 2 = 5 and then doing something with the remaining2

#

I guess adding it

#

but it should be multiplication

earnest phoenix
#

Just implement the ordinary syntax mmLol

sharp geyser
#

NO

#

Now I am committed

earnest phoenix
sharp geyser
#

Okay now what the fuck is happening

#

the result is 8 now

#

OKAY WAIT

#

VOLTREX

#

I GOT IT

radiant kraken
#

congrats

sharp geyser
#

@wheat mesa hey buddy I got it to work

radiant kraken
#

thru trial and error

sharp geyser
#

with help from null

#

and volty

radiant kraken
sharp geyser
#

I actually learned a lot here

#

Now I know how to convert a string to an int at least

radiant kraken
#

with the help of me topggSunglasses

sharp geyser
#

not only that I understand more on how vectors work

radiant kraken
#

poggers

sharp geyser
#

Ima move this code to another file

sharp geyser
radiant kraken
#

ok from now on dont consult me

#

ask brain

sharp geyser
#

lmao

#

its okay

#

I got brain added

#

he on speed dial

radiant kraken
#

wdym?

sharp geyser
#

he in my friends list

radiant kraken
#

damn i didnt know he accepts friends

sharp geyser
#

I was shocked he even accepted it

radiant kraken
#

lmao

sharp geyser
#

a long one at that

proud light
#

Hi

radiant kraken
#

good luck on that

sharp geyser
#

I got it installed, but doing the cmake stuff for it

#

Not ready for cmake

#

it is pain

#

so ima stick with projects that dont require a package for now

neon leaf
whole knot
stiff dust
#

Hello, my bot is now have 7.5K servers its not count as very very big bot buts its big enough to create spam!
I need to check server language on all of commands or for example for any message sent on any server I need to check is that message.channel seted up as media only channel or not. so as a result of it I have to send a request to mongoDB to access to my Data Base and check it what should I do?

digital swan
#

cache db response with redis or something

lyric mountain
#

doesn't most reputable database libraries already cache data?

deft wolf
#

I think that if mongodb had a problem with handling a bot that is on 8,000 servers, it would not be such a popular database KEKW

#

Of course, mySQL probably seems faster, but your database won't fall apart

lyric mountain
#

depends kinda, mongo will be faster for arbitrary data access, regular sql will be faster for structured data

stiff dust
sharp geyser
#
int CheckingAccount::ChangeBalance(int new_balance) {
    return this->balance = new_balance;
}

Would this return the value of balance after its set or would it return the old balance.

stiff dust
#

but I just dont want to request data all time

stiff dust
#

and also which one is better for sharding? own djs shardingManager or discord-hybrid-sharding?

sharp geyser
#

just use the djs sharding manager ngl

#

with how djs is now the hybrid sharding one is obsolete imo

#

Not to mention if you really wanted, you could just turn on auto sharding and call it a day.

stiff dust
#

so why many devs still use it? thinkLul

sharp geyser
#

Not saying its not good

#

I just feel its no longer really needed

stiff dust
#

hmmm

#

ok tnx peepoRose

sharp geyser
#

If you want something easier though, you would wanna go with discord-hybrid-sharding

#

it has built in stuff to make it a little easier than just turning auto on

#

which uses your recommended shard count.

stiff dust
#

no I guess Im gonna try DJS Sharding

wheat mesa
sharp geyser
#

ALSO

#

didn't know if I told you

#

but I got the RPN thing to work

#

:D

wheat mesa
#

Nice!

sharp geyser
#

null and voltrex helped me in the end

wheat mesa
#

Good little exercise for learning how istringstream works too

sharp geyser
#

but I managed to figure out the general idea

#

Now I am working on a mock bank app

#

So I can learn about classes and headerfiles

wheat mesa
#

Always fun stuff

sharp geyser
#

yessir

wheat mesa
#

You should also learn about pointers and such sometime

#

Perhaps try implementing your own vector class (but without templates, just for ints or something)

sharp geyser
#

Im sure I can make use of them in this somehow

wheat mesa
#

That’ll be good for pointers

wheat mesa
#

That’ll teach you the basics of allocation and deallocation

sharp geyser
#

Isn't vector just a dynamic array

wheat mesa
#

Yes

sharp geyser
#

I'll try it out after this mock bank app

sour stream
#

guys

#

nvm

deft wolf
#

Okey

neon leaf
#

its time 🙏

#

I finally got myself a proper pc

#

got it free actually

#

ordered a rtx 4060 for it

tulip ledge
neon leaf
#

ye its fine

#

i3 12th gen

#

18% bottleneck

sharp geyser
#

I dont remember how to check bottle necks

#

I think this is accurate

#

not terrible

#

I do want to eventually upgrade my cpu

#

just not sure what to

#

and if I do that, I might as well upgrade my mb as well so I can utilize ddr5 ram

stiff dust
sharp geyser
#

?

stiff dust
#

DJS Sharding is heavier

#

when I start my bot with Hybrid Sharding it takes 1GB ram

#

and now

#

with same amount of shards

#

it takes 1.5GB

sharp geyser
#

So just normal djs starts with 500mb morr

#

or is that with hybrid

stiff dust
#

normal djs starts with 500mb more

sharp geyser
#

Damn I thought they made it better

stiff dust
#

as it start 8 different shard and everything work 8 times for example 8 ready.js but in hybrid it was only 2 ready.js as I had 2 Cluster and 4 shard in each cluster so there was same shard count but different usage

sharp geyser
#

tf

#

Ah right djs doesn't do clustering like hybrid does

#

forgor

tulip ledge
#

You wont get full performance out of your gpu

neon leaf
#

I know

#

I plan on upgrading cpu later

#

the socket is nice

stiff dust
sharp geyser
#

If you want clustering hybrid

#

unless you want to do it yourself with djs

#

I forgot djs has yet to implement such a thing

#

Which is surprising considering how much they hold bot dev's hands anyway

stiff dust
frosty gale
radiant kraken
wheat mesa
#

Same C:

sharp geyser
#

Same C:

#

Thanks guys

proven lantern
heady quarry
#

Ah

proven lantern
errant flax
#

can someone explain to me whats a normal? (in vector)
have googled the term still dont understand it

neon leaf
lyric mountain
#

Normalizing them is simply converting them to 0...1 range

#

Like 40, 100, 10 would become 0.4, 1, 0.1

sand knoll
earnest phoenix
civic scroll
#

love are you out of your mind

radiant kraken
civic scroll
#

but why must he torture himself like that

radiant kraken
#

he was bored?

#

i mean

#

don't you write SVGs all day

sharp geyser
#

Almost 800 lines on a phone

#

Buddy, thats not just being bored

earnest phoenix
#

Dedication mmLol

sharp geyser
#

Also just want to point out

#

I never would of been able to do something like that with my current knowledge

radiant kraken
#

obviously

#

he just wanted to show off

civic scroll
#

@earnest phoenix @radiant kraken sayulang gx_tro

#

oh shit to is supposed to be a keyword

#

fixed

radiant kraken
civic scroll
#

textmate

#

idk what i'm doing

radiant kraken
civic scroll
earnest phoenix
wheat mesa
#

It looks pretty close to what I made in C#

#

Granted I based it off of the crafting interpreters implementation

earnest phoenix
wheat mesa
sharp geyser
#

Was just about to link it

#

lol

wheat mesa
#

This was one of the first projects I did when I was getting into parsing, pretty proud of adding the whole “MathLibrary.cs” file to it, it feels easy to use and extensible

earnest phoenix
#

As much as I like the visitor pattern, it's incredibly hard to implement in programming languages that have extremely strict type systems like C/C++ and Rust

wheat mesa
#

Yeah

#

It’s really annoying, which is why I much prefer rust’s type system for interpreters and such

#

Versatile pattern matching + a flexible type system for representing recursive structures = a beautiful interpreter

eternal osprey
#

hey guys i have written my own algorithm for a school project where we had to return the minimal amount of boxes by fitting each and one other

#

anyways

#

i ran my code through an online "chat gpt detector"... it returned me fucking 55%

#

i didn't even copy code from chatgpt, only asked questions about what some issues were and how to fix them lmao

neon leaf
eternal osprey
#

my university really bitches on that type of stuff

#

but the thing is, i literally coded everything myself

#

so why the fuck is chatgpt zero highlighting me as 54% ai generated?

#

the stuff it highlighted are really strange as well, such as importing packages, variable names, function signatures..?

earnest phoenix
#

ChatGPT Zero is really bad at detecting AI vs hand-written code

neon leaf
#

because code doesnt have as much possible variation as normal text

eternal osprey
#

i see, i hope that my school isn't using that then..

#

they are probably using moss of stanford

#

heard it's a good one

gray mauve
#

h

wheat mesa
earnest phoenix
#

Oh, yeah I would assume that there would be a default base 10 radix as well

wheat mesa
#

Or maybe there is a version that assumes base 10 and I just didn’t see it when I wrote that

neon leaf
neon leaf
#

I hate this more

#

rebuilding broken raid

sharp geyser
neon leaf
#

yea especially the part where it takes 3 hours

lyric mountain
#

]

#

ops

#

hate when the focus is in some background app

wheat mesa
#

Does anyone have recommendations on how to efficiently store and process objects in a physics simulation? Last time I used an ECS, but I felt like I had difficulty achieving flexible behavior

#

Not sure if I should go after that again, or if I should try some other structure

neon leaf
#

99% done

#

2am

eternal osprey
#

hey guys

#

has anyone any recommendations on how to make this look better

#

idk the products are looking dookie for some reason but i can't place it.

sharp verge
eternal osprey
#

i see, thank you for the help!

radiant kraken
deft wolf
#

Actually, wouldn't it be better to move this black stripe with stars to the footer? It's probably a matter of taste, but I feel strange when there is a number of stars in the upper right corner, the footer seems to me a better place for such information than the very top of the page

rocky wave
#

How do i add the feature of sending voice messages to my discord bot

#

Like just send an mp3 file as voice message

pale vessel
radiant kraken
#

i mean it's okay if it's for the mobile version but

#

imo it needs to be a bit wider

eternal osprey
#

hey java gurus, i have a question:

I am creating an algorithm to return the minimal amount of boxes needed. One box can fit in another box based on permutations. So suppose a box has dimensions [x,y,z], then you must check all permutations of the box as:

A box fits if there exists a permutation such that x > x of other box, y > y of other box, z > z of other box.

Right now this is my output of my FIRST box splitter:

[[[0.747756, 0.642319, 0.569011], [0.514339, 0.583412, 0.660649]], [[0.556423, 0.772266, 0.755868], [0.675496, 0.705229, 0.544096]], [[0.678271, 0.663318, 0.571389]], [[0.842022, 0.73891, 0.698524], [0.622235, 0.8074, 0.632252], [0.673077, 0.708456, 0.570999], [0.757113, 0.634282, 0.610887]], [[0.605403, 0.879344, 0.840328]], [[0.796699, 0.95473, 0.81393], [0.579564, 0.879689, 0.736052], [0.571137, 0.532766, 0.936874], [0.932276, 0.591703, 0.658759], [0.945931, 0.652785, 0.737563], [0.88937, 0.538176, 0.534113]], [[0.871447, 0.690473, 0.88035]], [[0.777473, 0.892142, 0.962822], [0.579407, 0.848634, 0.925978]], [[0.803432, 0.860415, 0.956237]]]

However, in my recursive call it goes horribly wrong:

#
public static void boxFitter() {
        boolean hasChanged = false;
            for(int i = 0; i < boxPartitions.size(); i++){
                for(int j = 0; j < boxPartitions.size(); j++){
                        if(isSmaller(boxPartitions.get(i).get(0), boxPartitions.get(j).get(0))){
                            boxPartitions.get(i).addAll(boxPartitions.get(j));
                            result.add(boxPartitions.get(i));
                            boxPartitions.remove(boxPartitions.get(i));
                            boxPartitions.remove(boxPartitions.get(j));
                            i= 0;
                            j= 0;
                            hasChanged = true;
                        }
                }
            }
            if(boxPartitions.size() > 1 && hasChanged){
                boxFitter();
            }else if(boxPartitions.size() == 1 && hasChanged){
                Vector<Double> toCheck = boxPartitions.get(0).get(0);
                for(int i = 0; i < result.size(); i++){
                    if(isSmaller(result.get(i).get(0), toCheck)){
                        result.get(i).addAll(boxPartitions.get(0));
                        boxPartitions.remove(boxPartitions.get(0));
                    } else if(boxPartitions.size() == 1 && isSmaller(toCheck, result.get(i).get(0))){
                        result.get(i).addAll(0, boxPartitions.get(0));
                        boxPartitions.remove(boxPartitions.get(0));
                    }
                }
            }

    }```
#

it returns me fucking 4 instead of 9 for the minimal boxes. i just need any help on how to progress further and if someone sees the issue..

lyric mountain
#

I...have no idea of what you asked

#

but a thing is for sure, you need to optimize those accesses

sage bobcat
eternal osprey
#

They want you to fit boxes inside each other if they fit, meaning that there’s a permutation of the 2 boxes where the dimensions of one box are all bigger than the other.

#

But for some reason the above method isn’t really doing the job correctly. It partitions the boxes the wrong way

sharp geyser
#

@wheat mesa when it comes to making my own vector implementation, how do you advise I start off?

#

My thought process is a bit flawed

sharp geyser
#

@earnest phoenix what’s your thoughts on this? I want to try and implement my own vector class, but only supporting ints. Waffle said it’d help with learning pointers and references as well as allocation and deallocation

#

I just simply don’t know where to start. I was going to treat it like a dynamic array that can take an endless amount of values but I don’t know how to achieve this without actually using vector itself.

#

Which defeats the purpose if I use the built in vector

#

I know arrays work by doing type[size] but I don’t know how I’d make that dynamic

frosty gale
#

usually whats done is you allocate x amounts of ints in your case as an array with an allocator to start off with so you have a plain c array to work with

frosty gale
#

then array references the start of the first int so you can set data on it at specific indexes as usual

#

theres no boundary checks tho thats for you to implement in a custom vector

#

or you can simply use a c++ array (std::array) which is a bit more intuitive and safer to work with to make the array 🤷‍♂️

sharp geyser
#

I see

#

Yea I’m quite new to c++ so allocation and deallocation are foggy subjects for me

sharp geyser
frosty gale
#

you can make the user provide the initial size of the internal array but whats usually done is c++ starts with some number (it can be anything) as the initial size for the vector array and then grows it once more elements are inserted

#

you should focus on setting/deleting/initiating the vector first though leave growing/shrinking the internal array for last

sharp geyser
#

So it has a default size but its size can be modified depending on what’s allocated to the array?

frosty gale
#

essentially yeah

#

the initial size is usually something that balances the performance of inserting the first few elements and not having too excessively big of an array for no reason

sharp geyser
#

Makes sense

frosty gale
#

but it really doesnt matter too much can be something on the top of your head like 5 or something or whatever you like

sharp geyser
#

Yea in reality it just needs to be something to start the vector off with

#

Well thanks a lot for your advice

#

I’ll try and see if I can get something started

frosty gale
#

yeah try keep it stupid simple at first so you dont get too ambitious without knowing how to do certain stuff

#

one thing at a time!!

earnest phoenix
#

Pretty much every compiler that implements vectors does this

radiant kraken
#

@sharp geyser ```cpp
const int size_of_each_element = sizeof(int);
int * pointer = (int *)std::malloc(initial_capacity * size_of_each_element);
// pointer[0], pointer[1], etc...

if (pointer == nullptr) {
// system out of memory
}

// resize the vector to a new capacity
pointer = std::realloc(pointer, new_capacity * size_of_each_element);

// deletes/frees the memory back to the OS. this MUST be called once you're done with the vector, otherwise you have a memory leak
std::free(pointer);

sharp geyser
#

I see

#

Ima try and implement something similar tomorrow later today after I wake up

#

Since its my day off

radiant kraken
sharp geyser
#

I wasn't too sure how to free the block of memeory

earnest phoenix
sharp geyser
#

but then I remembered there was delete keyword

earnest phoenix
#

Because std::malloc() has a much higher overhead than just a simple check

sharp geyser
#

what is the difference between using malloc and just new

radiant kraken
#

both basically does the same thing

sharp geyser
#

so is it better to use new over malloc?

radiant kraken
#

no imo

sharp geyser
#

or for learning purpose is it better to use malloc

earnest phoenix
#

new calls the constructor where malloc() does not

radiant kraken
#

^ new is good for classes

sharp geyser
#

so with malloc i'd have to do a lot more checks myself.

radiant kraken
#

yes

#

because malloc is a C function

sharp geyser
#

right right

radiant kraken
#

if you're using raw C structs (without constructors) or primitive types (pointers, ints, chars, etc) go for std::malloc, otherwise if you're going for classes/structs with constructors go for new

sharp geyser
#

So when implementing my own custom class, it entails a headerfile as well. I am still not used to what to do in those. I know I should be outlining what is included int he cpp file but when it comes to outlining what a class is I am clueless.

radiant kraken
#

so are you working on a library of some sort

sharp geyser
#

Not really

radiant kraken
#

e.g you want to keep things in separate C++ files

earnest phoenix
# radiant kraken wdym

std::malloc() has multiple steps and branches that it goes through before bailing out and returning a nullptr indicating failure, whereas you can know ahead of time that it goes beyond the capacity so you can optimize it further with a simple capacity check

sharp geyser
#

Just messing around in c++ and waffle recommended to make a vector implementation

radiant kraken
#

ah

sharp geyser
#

so I thought i'd just make it a class so I can mess with headerfiles as well

radiant kraken
#

then since you're still a beginner then i recommend write the class definition in a C++ header file

sharp geyser
#

wdym? Isn't that what I was asking about

earnest phoenix
#

You basically just only write the types of what the class contains (declaration), not the bodies (definition)

radiant kraken
#

that should be for later imo, linking can get a bit complicated for a beginner

#

unless his IDE got his back or something

sharp geyser
#

CLion always got my back

radiant kraken
#

voltrex writing a long essay null_stare

sharp geyser
#

He on phone

earnest phoenix
#

Example:

foo.h:

#ifndef FOO_H
#define FOO_H

class Foo {
 public:
  int foo;

  Foo(int foo);

  int bar(int baz);
};

#endif  // FOO_H

foo.cpp

#include "foo.h"

Foo::Foo(int foo) : foo(foo) {}
int Foo::bar(int baz) const { return foo + baz; }
radiant kraken
#

not main.cpp

#

foo.cpp

#

main.cpp should be for the main function/program startup/shutdown

earnest phoenix
#

Did you look at the bottom?

#

It's an example, but yes it should be separated

#

There

radiant kraken
#

also, why not ```cpp
#include "foo.h"

Foo::Foo(int foo): foo(foo) {}
int Foo::bar(int baz) { return foo + baz; }

#

i've seen some examples do this

earnest phoenix
#

Yes that is correct way actually

earnest phoenix
radiant kraken
sharp geyser
#

@earnest phoenix @radiant kraken so what does int* array; do?

#

I notice that when messing with it in code, it seems to create a one dimensional list/array/something

#

as I can do array[1] and assign stuff to it

#

but I am not sure if I am mistaken

sharp geyser
#

I don't know how to really explain it any better

#

I simply don't understand what int* array is.

#

like int array obviously means that array will hold a number

radiant kraken
#

yes

sharp geyser
#

but adding an asterisk and what the end behaviour is I don't know

#

I guess thats as simple as I can get my question

radiant kraken
#

int * array is a pointer to an int in memory

sharp geyser
#

I see

radiant kraken
#

If you think about it arrays in C/C++ are just pointers to the first element

#

array[1] is the memory address array + index * the size of each element in array, in this case sizeof(int)

sharp geyser
#

I am just trying to figure out the best method of holding onto the array once its been allocated

earnest phoenix
# sharp geyser <@456226577798135808> <@661200758510977084> so what does ``int* array;`` do?

It creates a pointer to an int, the * in types denotes a pointer, meanwhile in body it denotes deferencing a pointer (accessing its value), if you read the declaration from right-to-left, it is a * (pointer) to int

Pointers are the addresses of values separated by value size in memory, which can be assigned either the value itself or an array of it

int* p can hold either an integer or an array of integers, but when the latter, it'll decay to the first element of the array, and you can access the others using the subscript operator ([]) or by pointer arithmetic (p++ = shift by sizeof(int))

However, int (*p)[5] is a pointer to a whole array of 5 integers (not just the first element), so it can't hold just an integer, and doing pointer arithmetic on an this will shift the array by sizeof(int) * 5

sharp geyser
#

I see

radiant kraken
#

int thing[] is only for array literals

#

not dynamic arrays

earnest phoenix
#

^

radiant kraken
#

volt u dont really need long essays for everything mmLol

earnest phoenix
#

I do for explaining things in detail

sharp geyser
#

So for my vector implementation I want to have an internal array correct? So would in my headerfile would I do something along the lines of

class {
private:
  int* array;
public:
  Vector();
}
Vector::Vector(){
  this->array = new int[1]
}

or something along these lines

radiant kraken
#

it's better to explain things in simpler terms

radiant kraken
earnest phoenix
#

I'm explaining it in simpler terms in more detail

sharp geyser
#

and with each new element the capcity changes as a new array is made

radiant kraken
#

sure

radiant kraken
earnest phoenix
#

Make a capacity field that keeps track of the capacity so you can easily check it on push

radiant kraken
#

ngl sounds like a useless feature

radiant kraken
eternal osprey
#
public static void createBoxPartitions() {
        while (!inputBoxes.isEmpty()) {
            Vector<Vector<Double>> currentBox = new Vector<>();
            Vector<Double> firstBox = inputBoxes.remove(0);
            currentBox.add(firstBox);

            for (int i = 0; i < inputBoxes.size(); i++) {
                if (isSmaller(firstBox, inputBoxes.get(i))) {
                    currentBox.add(inputBoxes.get(i));
                    inputBoxes.remove(i);
                    i = 0;
                } else if (isSmaller(inputBoxes.get(i), firstBox)) {
                    currentBox.add(0, inputBoxes.get(i));
                    inputBoxes.remove(i);
                    i = 0;
                } else {
                    Vector<Vector<Double>> distinctBox = new Vector<>();
                    distinctBox.add(inputBoxes.get(i));
                    inputBoxes.remove(i);
                    boxPartitions.add(distinctBox);
                    i = 0;
                }
            }
        }

}

For some reason my algorithm partitions all boxes in 4 boxes rather than 6. Would anyone know why?

sharp geyser
#

who needs a length field

#

when I can just make a size method

radiant kraken
#

wdym?

eternal osprey
#

This is the isSmaller function:

 public static boolean isSmaller(Vector<Double> largerBox, Vector<Double> smallerBox) {
        Vector<Double> sortedLargerBox = new Vector<>(largerBox);
        Vector<Double> sortedSmallerBox = new Vector<>(smallerBox);
        Collections.sort(sortedLargerBox);
        Collections.sort(sortedSmallerBox);

        for (int i = 0; i < 3; i++) {
            if (sortedLargerBox.get(i) <= sortedSmallerBox.get(i)) {

                return false;
            }
        }

        return true;
    }```
radiant kraken
#

go ahead then mmLol

#

gl

sharp geyser
#

Who doesn't like getting the size of the internal array each time you need the size of it

radiant kraken
#

wha

#

how do u do tho

sharp geyser
#

idk man im tired

radiant kraken
#

you cant

sharp geyser
#

its 3am

radiant kraken
#

you HAVE to store a length field

#

because its impossible to determine without one

sharp geyser
#

I was trying to sleep but this vector thing wouldn't allow me to sleep

#

😔

radiant kraken
#

go to bed then

sharp geyser
radiant kraken
#

gl finding a way

earnest phoenix
sharp geyser
#

that is all still a bit confusing

#

but with practice I will surely understand it

radiant kraken
#

i mean what are the use cases for it

#

i need a real world example

sharp geyser
#
int* Vector::insert(int element, int index = 0) {
    int* temp = this->array;
    this->capacity += 1;

    for(int i = this->length; i >= index; i--) {
        temp[i] = temp[i - 1];
    }
    
    temp[index - 1] = element;
    
    int* newArray = new int[this->capacity];
    
    newArray = temp;
    
    delete this->array;
    
    this->array = newArray;

    return this->array;
}

Okay this is my shitty implementation of inserting an element into the vector at a specific index.

#

Please tell me I am at least close

#

😩

radiant kraken
#

nope

#

use realloc

sharp geyser
#

FUCK

#

why realloc?

radiant kraken
#

because its much more efficient and faster

#

and doesnt have to delete and make a new array

sharp geyser
#

I see

earnest phoenix
# radiant kraken i need a real world example

Enforcing good memory management practice

#include <cstring>

void print_p(int* arr) {  // no size information
}

void print_a(
    int arr[5]) {  // the `[5]` is redundant here and is not enforced as the
                   // array decays to a pointer, losing size information
}

void print_pa(int (*p)[5]) {  // size information is not lost
}

int main() {
  int* p = new int[10];

  memset(p, 0, 10 * sizeof(int));

  print_p(p);  // OK, unexpected

  int a[10];

  memset(a, 0, 10 * sizeof(int));

  print_a(a);  // OK, unexpected

  int(*pa)[10] = &a;

  print_pa(pa);  // compiler error, expected
}
radiant kraken
#

that's so weird

#

i doubt people actually use that

earnest phoenix
#

People do, a lot actually

radiant kraken
#

where?

earnest phoenix
#

I'm not gonna go through lots of repositories to find where exactly they are used but they're used in critical places, such as mission-critical projects

radiant kraken
#

mission-critical?

sharp geyser
#

Okay so wait

#

I would use realloc to change the size of this->array and then I would then change what this->array is

earnest phoenix
sharp geyser
#

I am just basing this off of reading cppreference

#
    int* newArray = (int*) std::realloc(this->array, this->capacity);

    if(newArray != nullptr){
        this->array = temp;
    }

so something like this

radiant kraken
sharp geyser
#

So I ended up doing it correctly

#

Now next question

#

actually no

#

let me test first

#

before asking

radiant kraken
#

insane

#

not many people in development actually do that

sharp geyser
#

I gotta try and learn

#

so I wont ask a question until I am truly stuck

#

Though actually I do have a question

#

does c++ have the concept of optional arguments

radiant kraken
#

yes

sharp geyser
#

Cause I notice despite giving index a default of 0

radiant kraken
#

look up std::optional<thing>

sharp geyser
#

when using said method it still expects 2 arguments

#

Ah

#

Gotcha

#

thanks <3

#

now to truly test

radiant kraken
#

<3

#

@sharp geyser oh besides did you know something about ```cpp
Class::Class() {
// size zero
}

Class::Class(int size) {
// with size
}

#

afaik that is also possible

sharp geyser
#

Wait what

radiant kraken
#

@earnest phoenix afaik there's default constructors and all that, what are they for?

sharp geyser
#

Oh right just realized something

#

I can't treat this like it is an array

#

as its a class

#

I just tried doing vec[0]

earnest phoenix
sharp geyser
#

I knew of overloading

#

I didn't know c++ had it

earnest phoenix
#

Both C and C++ have it

sharp geyser
#

so I could technically make it so they can supply a size themselves?

radiant kraken
#

C does not have operator overloading???

radiant kraken
earnest phoenix
sharp geyser
#
Vector::Vector() {
    this->capacity = 1;
    this->array = new int[1];
    this->length = 1;
}

Vector::Vector(int size) {
    this-> capacity = size;
    this-> array = new int[size];
    this-> length = size;
}
radiant kraken
#

yuhh

sharp geyser
#

Okay

#

So another thing

#

Is there anyway I can make Vector vec; be treated like an array

#

so once I make a new vec instance

#

I can do vec.insert(199) -> vec[0]

#

to get the first element

sharp geyser
#

Oh

#

is operator a placeholder?

radiant kraken
#

yes

#

its for operator overloading

#

its a keyword

earnest phoenix
radiant kraken
#

oh if you want for the values to be modifiable, return a int &, (int reference)

radiant kraken
sharp geyser
radiant kraken
#

which part do u dont get?

sharp geyser
#

How it is supposed to work

radiant kraken
#

when you try

#

object_instance[index], it automatically calls that method

civic scroll
radiant kraken
#

sis this is not rust

civic scroll
#

wait whay

radiant kraken
#

wait i thought you were returning index

earnest phoenix
radiant kraken
#

then

#

how is array[thing] = 69; possible

civic scroll
#

pointer + offset

radiant kraken
#

array is a vector class

earnest phoenix
radiant kraken
#

oh wait

civic scroll
#

it's still continuous memory reason

radiant kraken
#

is it just void Vec::operator[](int index, int value) {} ?

civic scroll
#

nope

radiant kraken
#

operator[]=() or something

#

i forgor

civic scroll
#

in this case it would be a pointer deref

sharp geyser
#
// in Vector.h
int operator[](int index) const;
//in Vector.cpp
int Vector::operator[](int index) const {
    return this->array[index];
}

so something like this?

radiant kraken
#

yes

sharp geyser
#

my IDE pushed the const onto it

radiant kraken
#

thats good

sharp geyser
#

I assume I don't want it modifiable

civic scroll
radiant kraken
#

because it detects that ur function does not modify the class's properties

radiant kraken
#

it's the convention if you don't want to create a single-header library

civic scroll
# sharp geyser Wdym

like

class Vector {
public:
    int operator [] (int index) const { ... }
}

in the cpp side

radiant kraken
#

that's if you want to make a header-only library

civic scroll
#

wym?

radiant kraken
#

the convention is to separate the class definition and the class method bodies

civic scroll
#

it also has the implementation there, how come it only generates headers

radiant kraken
#

between the header file, and the c++ source

#

so you keep things organized

sharp geyser
#
In file included from C:/Dev/Vector/main.cpp:2:
C:/Dev/Vector/Vector.h:19:32: error: no template named 'optional' in namespace 'std'
   19 |         int* insert(int element, std::optional<int> index);
civic scroll
#

can i just use something else to automatically generate headeds from my class

radiant kraken
#

#include <optional>

earnest phoenix
sharp geyser
#

I did

civic scroll
#

L
rust has that built-in
smh

radiant kraken
#

YUHHHHH

#

FORREAL

sharp geyser
#

see?

#

it is included

radiant kraken
#

maybe its in #include <utility>

#

iirc

sharp geyser
#

tried that as well

#

and it asks me to include header optional

civic scroll
#

wait...

sharp geyser
#

lol

civic scroll
#

you didn't do any checks for array accessing?

sharp geyser
#

in due time

#

:C

civic scroll
#

boutta do the ```
Vector{}[1024]

sharp geyser
#

Go for it

radiant kraken
#

if (index >= this->length) { yeet }

sharp geyser
#

I dont even know how to throw errors in c++

#

😭

radiant kraken
#

throw ErrorClass("idk")

#

throw std::exception("idk")

sharp geyser
#

wait really

#

bruh

radiant kraken
#

insane i know

civic scroll
#

throw "bruh"

#

trol

radiant kraken
#

return Err();

#

trol

earnest phoenix
sharp geyser
#

No idea

earnest phoenix
#

std::optional requires C++17 or higher

civic scroll
#

what ide you in

sharp geyser
#

I think c++ 20

civic scroll
#

you think?

sharp geyser
#

Well tbh sayu

radiant kraken
#

he's in CLion

sharp geyser
#

I started this recently

#

smh

civic scroll
#

same

#

smh

#

what ide

sharp geyser
#

CLion

civic scroll
#

open settings

sharp geyser
#

it standard was set to C++ 20

civic scroll
#

oh

#

ok

#

then why

sharp geyser
#

Good question

#

No idea