C++ Logo

std-proposals

Advanced search

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

From: organicoman <organicoman_at_[hidden]>
Date: Wed, 31 Jul 2024 00:01:37 +0400
    auto var = make_auto<double>(); var.printTypes(); // prints double and int cout << typeid(var).name() << endl; cout << var << endl; int var2 = var; cout << var2 << endl; d -> doublei -> int11AutoWrapperIdiE -> AutoWrapper<double, int>123 -> value123 -> valueThat's not bad at all, definitely you're smart.👏Outside block scope, that definitely can work,But as soon as you put it inside a struct,You will be obliged to add the template parameters of AutoWrapper to the struct, Which is not the desired effect. Which will breakany existing code.Look at this example with the proposed change in effect.template<typename T>int globalVar;struct A{ using meta_int = effective_decltype(globalVar<T>); // (int)<T> meta_int m_data; A(meta_int arg) : m_data(arg) {}void printTypes() const{ // this should print "i" for integer. cout << typeid(m_data).name() << endl;}void introspection() const{ using templ_type = std::extract_1st_templ_type_t <effective_decltype(m_data)>; //at this stage m_data is fully constrcuted // so its effective type has a resolved template // parameter. cout << typeid(templ_type).name() << endl;};As far as the constructor of A above is concerned, it accepts argumentof 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 data when needed.With AutoWrapper class in your example, You have to be intrusive, and any data member of AutoWrapper type, imposes at any class tobe templated. Thus that class cannot be used as a container template parameter.This proposal can be summarized, with the following:An effective type is a regular apparent type tagged with some meta data, if needed,that only the compiler can make sense of and manipulate, and will not change the behavior of any existing program.PS: Between me and you, for a moment i wasshocked, I thought you found the solution.You are different, that's a fact ;-)

Received on 2024-07-30 20:01:50