This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: type traits, reflection, and whatnot


On Sun, Jan 12, 2003 at 03:26:36PM +0100, Gabriel Dos Reis wrote:
> Hmm, can you elaborate on he difficulty you're talking about?  E.g.,
> what is difficult about
> 
>     // type_traits.h
> 
>     namespace std
>     {
>        template<tyename T>
>          struct is_scalar {
>              static const bool value = __is_scalar(T);
>          };
> 
>        template<typename T>
>           const bool is_scalar<T>::value;
>     }
> 
> ?

It's annoying and repetitive.


> | a rarely-taken code path in pt.c starts to instantiate the template,
> | notices that the type is still incomplete, then checks for the presence
> | of one of the traits classes. 
> 
> Ah, yes, I've thought about this strategy in the past, and finally
> concluded that it is too fragile and less scalable.

I think this is far more scalable than you think, but it's a moot point.


> I don't think this is an intrinsic advantage of the path you're
> taking.  Let me rewrite what I proposed earlier as:
> 
>    template<typename T>
>      struct is_scalar : __gnu_cxx::_Bool2Type<__is_scalar(T)> 
>      {
>      };

That would work nicely; I would go with this.


> On the other hand hardwiring things in pt.c means one has to
> check many places for special templates.  Many checks means equally
> opportunities to miss bits.

No, only one place.  There's a single change in pt.c, a single 'if'.

I'm assembling some furniture today and tomorrow, but if I could get the
code polished off and show you the diffs, I think you might be surprised
at how easy it was.


Phil

-- 
I would therefore like to posit that computing's central challenge, viz. "How
not to make a mess of it," has /not/ been met.
                                                 - Edsger Dijkstra, 1930-2002


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]