set_input_approver(3)

πŸ“¦ version 1.6, in fedora 43, fedora 44

set_input_approver πŸ’…

ok so bestie, welcome to set_input_approver(3) from the gstream manual ✨ this one lives in section 3 and it's genuinely such a cute little function, let's get into it πŸŽ€


🌸 NAME 🌸

set_input_approver β€” the gatekeeper of your input, fr fr πŸ‘‘


✨ SYNOPSIS ✨

#include <gstream.h>

void set_input_approver(bool (*input_approver)(int));

πŸ’– DESCRIPTION πŸ’–

okay so here's the tea πŸ“ the function you hand over gets called with every single new character that gets inputted, and it decides whether the inputter is gonna accept that character or not. The way it works:

  • if it returns true β†’ the character is accepted and inserted into the input string πŸ’–
  • if it returns false β†’ the character is thrown away πŸ—‘οΈ gone. deleted. not invited to the party.

A short example, since seeing it hits different:

bool ia_abc_is_what_we_want(int chr)
{
  if (chr == 'a' || chr == 'b' || chr == 'c')
    return true;
  else
    return false;
}

//...

gs.set_input_approver(ia_abc_is_what_we_want);
gs >> my_string; // the user is only able to input a, b or c

so iconic honestly, the user literally cannot type anything except a, b or c 😭 slay.

Now β€” if you wanna declare any variables of the type of the function, there's a typedef called input_approver in gbuf that makes it super easy, like:

gbuf::input_approver tmp_ap;

//...

tmp_ap = gs1.get_input_approver();
gs1.set_input_approver(gs2.get_input_approver());
gs2.set_input_approver(tmp_ap);

look at them swapping approvers, that's main character energy right there πŸ”₯

heads up bestie β€” note that a default input string as entered by set_input_string is not checked by this function. no vibe check for the default string, it just walks right in πŸ™ˆ

The default approver is

πŸ’€ not me… the page literally just stops there, no cap. that's all she wrote.

πŸ¦‹ SEE ALSO πŸ¦‹

go read those next, iykyk πŸ“šβœ¨


and that's the whole page, bestie 🫢 this was gstream, version 1.6 β€” the source and version on the original footer, mwah πŸ’‹ consider yourself blessed, periodt πŸŒˆπŸ‘‘

πŸ“¦ where this page comes from