[cfe-dev] Template Qualifier Removal Question

Andrew Gozillon via cfe-dev cfe-dev at lists.llvm.org
Mon Aug 13 02:29:20 PDT 2018


Hi Csaba,


Thank you for the quick reply! That's true it creates a new type, but I would like to know at the point of template instantiation where the typedef T type (from your example) is worked out from the original past in type within the compiler. If that's a thing that occurs of course.


I'm unfortunately not entirely familiar with how it works so I could be wrong, but I imagine the T component needs to be deduced at some point and separated from the const component. So that you'd end up with an int instead of an const int for example.


Sorry if I'm not making sense and I apologize for phrasing my initial question quite badly. I'll try to be a little more careful with my wording in the future.


Best Regards,

Andrew


________________________________
From: Csaba Raduly <rcsaba at gmail.com>
Sent: 13 August 2018 09:37:09
To: Andrew Gozillon
Cc: cfe-dev at lists.llvm.org
Subject: Re: [cfe-dev] Template Qualifier Removal Question

Hi Andrew,


On Mon, Aug 13, 2018 at 8:36 AM, Andrew Gozillon via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
> Hi,
>
> I have a question relating to template metafunctions like remove_const that
> split a type from its qualifiers.
>
> I was wondering where in Clang the decision to remove const (or another
> qualifier or pointer) from a type is made when using templates and then
> where it's performed (the new type generated)?

Are you talking about std::remove_const (
https://en.cppreference.com/w/cpp/types/remove_cv ) ?
std::remove_cv, std::remove_const, std::remove_volatile ...<https://en.cppreference.com/w/cpp/types/remove_cv>
en.cppreference.com
Provides the member typedef type which is the same as T, except that its topmost cv-qualifiers are removed.. 1) removes the topmost const, the topmost volatile, or both, if present.



I have bad news: std::remove_const doesn't remove const from a type.
It merely creates another type.

>From the "Possible implementation" :

template< class T > struct remove_const          { typedef T type; };
template< class T > struct remove_const<const T> { typedef T type; };

remove_const<T> creates a new type ( remove_const<T>::type ) which is
exactly the same as T,
except if T is const, remove_const<T>::type isn't.


Csaba
--
You can get very substantial performance improvements
by not doing the right thing. - Scott Meyers, An Effective C++11/14 Sampler
So if you're looking for a completely portable, 100% standards-conformat way
to get the wrong information: this is what you want. - Scott Meyers (C++TDaWYK)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180813/30a40d02/attachment.html>


More information about the cfe-dev mailing list