#Can I know how many classes/structs I use im my code

30 messages · Page 1 of 1 (latest)

tardy elk
#

I would like to define a struct for each type I use that just holds a type.

template<size_t S>
struct Reflector //Reflector
{
    using Type = void;
};
template<>
struct Reflector<63>
{
    using Type = sometype<3>;
};

I know I could do it by hand.
To really think which types i am using. Like float, std maps e.t.c.

But is there some way to make the computer automatically do this?

winter templeBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

high pasture
#

not really

#

but that's an X/Y problem

#

what you really seem to want is a unique ID for each type

#

so like, what problem are you actually trying to solve with this?

tardy elk
#

Well I am thinking I want a reverse function for

typeid(obj) -> gives id

:::
idtype(id) -> gives obj

high pasture
#

well 1) a type can have many objects

tardy elk
#

Maybe sth like
Using T = idtype(id).type

high pasture
#

for example typeid(5) -> int idtype(int) -> 5?

tardy elk
#

Exactly

high pasture
#

okay but I mean

#

the C++ typeid function

#

typeid(5) -> int, typeid(-5) -> int typeid(4.5) -> float

#

if I ask for idtype(int) do I get back 5 or -5?

high pasture
#

so why to you need this? just say the type you mean

tardy elk
tardy elk
high pasture
#

no you can't? You can not do a using T = <something from runtime>

#

T must be known at compile time

tardy elk
#

I am thinking to throw in a compile time integer.

And I made a converter from runtime to compile time for 0 - 128

high pasture
#

why do you need a compile time integer

high pasture
#

But where does the X come from? it's not from a runtime value

#

why does X need to be a compile time number

#

anyways, there are some terrible hacks you can use to kinda get an incrementing number at compile time (they get less bad if they don't have to be incrementing)
there are some quite standard hacks you can use to get a load time incrementing number for types, which is probably sufficient for the reflection you are trying to do

cinder heart
tardy elk
#

I will awnser tomorrow i think i am pretty tired and not able to give good explanation today. Local time 22:19

cinder heart