C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Function overload set type information loss

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Tue, 30 Jul 2024 22:49:40 +0200
Hi organicoman,   that is the whole point.   You want a compile time feature, where the compiler keeps the information, how an object is created. But then on the other hand, you want to store those objects into a container.   E.g. std::array<int32_t, N>   Where should this additional meta information be kept? The storing of values into the container is in the general case done at runtime. It could be dependent on user or file inputs. So the compiler (compile-time) cannot follow it any longer.   The array itself has a fixed size of 4*N bytes, just enough for the int. So we also cannot store type ids at runtime together with the ints themselves.   We loose the meta / extended type information.   It is not a language shortcoming, but there is no logical way to solve this for containers. You have to give up one of your requirements:   Either  - the container stores additional information (std::any like)  - all entries in the container will have the same meta type instead of an individual one  - it only works for containers clearly initialized in a way, which can be deduced at compile-time, e.g. std::array<int32_t, 5> myarray{1, 2, 3, 4, 5};  - it won't work with containers at all  - it only works for containers modified in consteval/constinit code (which the compiler may choose to run at compile-time)   Best, Sebastian   -----Ursprüngliche Nachricht----- Von:organicoman <organicoman_at_[hidden]> Gesendet:Di 30.07.2024 22:01 Betreff:Re: [std-proposals] Function overload set type information loss An:Sebastian Wittmeier via Std-Proposals <std-proposals_at_[hidden]>; CC:Sebastian Wittmeier <wittmeier_at_[hidden]>;   As far as the constructor of A above is concerned, it accepts argument of apparent type int, but as soon as we pass arguments with a signature like the globalVar above it will capture an effective type of this form (int)<T>  The type alias meta_int above, is just an int with some extra meta datawhen needed. With AutoWrapper class in your example, You have to be intrusive, and any data member of AutoWrapper type, imposes at any class to be templated. Thus that class cannot be used as a container template parameter.

Received on 2024-07-30 20:49:43