C++ fags help

if i want a class constructor to be able to take multiple default member arguments am i really forced to create a constructor for each? it seems very tedious when i have say 5-6 member variables that i want to be able to be initialized via the constructor.

is there some way i can just have one constructor that just "accepts" a list of any amount of arguments and then i specify which argument (if passed) should be used to initialize a member variable. Something like this:

Flag(std::crazy_stdlib_magic_args args): m_name(args), m_desc(args), m_alias(args){}

Attached: file.png (815x595, 45.34K)

and yes i realize two of the constructors are ambiguous that was just a mistake

The third parameter in the one on the bottom could accept an empty string as the default argument. Also, stop using const value parameters and member variables. It's completely pointless 99% of the time

Attached: Screenshot 2022-03-12 005207.png (637x97, 7.43K)

Use constructor delegation man

>The third parameter in the one on the bottom could accept an empty string as the default argument
i dont want the user to think they are forced to specify args they aren't. They might not know what to put there

>Also, stop using const value parameters and member variables
why? what if someone passes a flag object as a const? if i dont mark getters functions & the corresponding member variables as const, then they cant be called on that object

>i dont want the user to think they are forced to specify args they aren't. They might not know what to put there
nvm i see what u mean now

what colorscheme is that user? looks comfy

gruvbox

very dark gruvbox?

what an ugly language lol

Use optional arguments

i think its just default gruvbox with a dark bg

Attached: file.png (778x65, 3.85K)

>why? what if someone passes a flag object as a const?
It's irrelevant whether the actual parameter is const or not. It's also irrelevant whether the formal parameter is const std::string or std::string. The only difference between the two is that you are going to operate on a const std::string in the implementation of your function, it doesn't matter at all for its interface and objects that are used as actual parameters

>if i dont mark getters functions & the corresponding member variables as const, then they cant be called on that object
...What?

i see, thanks user

std::optional
and cool it with consts

Make an Arg struct
struct Arg {
int arg1, arg2, arg3, arg4, arg5
}

void func(Arg arg) {
if(arg.arg1) {doSomethingWithArg1(arg.arg1);}
// repeat for args 2-5
}

[\code]

>cool it with consts
Everything that can be const should be const. What OP needs to cool it with is PASSING STRINGS BY FUCKING VALUE.

>Everything that can be const should be const
Why

>fags help
>class named flag
>8 consturctors for the same thing
>virtual destructor
>shitty colorscheme
>CPL exceeded
>screenshot has chopped line numbers
my kind of art, right here

This is the basic, but the proper way is to understand wtf are you wanting 8 flags?
Are they all the same thing? Or derivatives of a single thing?
Dog inherits animal
Cat inherit animal
Kitten inherits Cat, default age=1, etc etc

Without specifics it’s hard to give an exact answer

Here are two options.
Either use the GNU struct extension that let's you construct object inline.
using std::string;
struct Flag
{
const string m_name;
const string m_alias;
const string m_desc;

bool m_set = false;
}

...

Flag flag = {
.m_set = true
.m_alias = "Alias";
.m_name = "My name";
};

Or use an unordered map or a fixed vector of pairs (the standard library does not have that iirc) for out of order construction
struct Flag
{
using args = unordered_map;
Flag(string_view name = {}, string_view alias = {}, string_view desc= {}, bool set = {})
:m_name(name), m_alias(alias), m_desc(desc), m_set(set)
{}
Flag(bool set, string_view name = {}, string_view alias = {}, string_view desc= {})
:Flag(name, alias, desc, set)
{}
// Constructor for out of order.
Flag(const args& arg, bool set = {})
:m_set(set)
{
if(arg.contains("name"))
m_name = arg["name"];
if(arg.contains("alias"))
m_name = arg["alias"];
if(arg.contains("desc"))
m_name = arg["desc"];
}
Flag(bool set, const args& arg)
:m_set(set)
{}

string m_name;
string m_alias;
string m_desc;

bool m_set = false;
}

...

Flag flag1 = {"name", "alias", "desc", true};
Flag flag2 = {{"alias", "123", "name", "2"}, false};
Flag flag3 = {{"desc", "aaa", "alias", "bbb"}, false};

Three typos.
Should be
Flag flag2 = {{"alias", "123"}, {"name", "2"}}, false};

I accidentally put name in every field of the constructor.
The final constructor should just be
Flag(bool set, const args& arg)
:Flag(arg, set) {}

This is the telescoping constructor antipattern.

Look into using the Builder pattern to avoid it.