Using Enums with Structual Bindings

Hi all,

I wanted to ask if it is possible to use Enums with Structural bindings? I am working through a practice exercise which builds on a previous example I came up with.

I am practising how to return multiple values from a function using a tuple.

> I built a class

> The class has an accessor/getter which returns a 4 tuple

> 3 of the elements of the tuple are strings which I can tie using structural binding

> the 4th element I've been trying to grapple with is of Enum type, with an underlying type char for the football players position.

Am I just chasing my own tail with this?

Any advice is very much appreciated.


Last edited on
is this what you need to see?
1
2
3
4
5
6
7
8
9
10
11

enum e{a,b,c,d};
tuple<string, string, string, e> foo()
{
	return make_tuple("big", "strong", "guy", a);
}

int main()
{
  	foo();	
}


I detect some confusion about enum, maybe. Think of enums as 'a group of constants'.
you can't get the text back out without code, eg you can't print on screen that 1 is 'b', its not like that. its just that you have a const b=1 built by that enum. The underlying type of enum is whatever integer the compiler picked for it, it 'may be char', but if it is a char, its not any kind of usable text, its just a 1-byte integer.

if you want the text you have to have code akin to:
if (variable == b ) cout << 'b';
or use parallel arrays inside your own 'better enum' class.
Last edited on
Hi Jonnin,

I hope you're not getting sick of hearing me say Thank You. I really do appreciate your help and insights..... so THANK YOU lol.
Topic archived. No new replies allowed.