You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by Travis Vitek <Tr...@roguewave.com> on 2008/05/24 01:37:10 UTC

type_traits progress

I've posted what I've got for the current type_traits implementation to
STDCXX-916. I would have just mailed the file to the list directly, but
it is pretty big.

    http://issues.apache.org/jira/browse/STDCXX-916

The tests do compile and run on VC8. There are still a few failures. I'm
in the process of porting this to linux/gcc4.3 and I'm expecting the
results to be a bit better there because all of the necessary compiler
support is available.

Please review the code and provide feedback. It would be most helpful if
any comments are pasted along with the block of code in question.

Also, please don't focus on formatting to much. I know that I have a few
lines that run over 76 characters wide and that I've left out some
spaces after commas and before open parens. I'll deal with that stuff on
my own.

Note that some of the tests have type names that end in underscores.
I'll be changing these to end in _t. It makes things more readable.

Travis

RE: type_traits progress

Posted by Travis Vitek <Tr...@roguewave.com>.
 

Eric Lemings wrote:
> 
>
> Travis Vitek wrote:
>> 
>...
>> 
>>   rw/_meta_other.h
>>     * __rw_enable_if
>>     * __rw_conditional
>> 
>> What do you think of this?
>
>Another possibility to consider is grouping them all in a subdir
>of the include/rw directory; e.g., #include <rw/meta/_cv.h>.
>
>I figure some C++0x components will need multiple header files
>rather than one or two huge 100k files.  It might make sense for
>such components to add a subdir within the include/rw directory.
>

You're killing me! Just when I thought this thread had died... :)

The discussion up to this point has led me to believe that the best
thing to do is to throw all of the internal trait implementations into a
single file and then separate out traits into their own files only as
necessary. I _really_ don't like this as it makes for one _very_ long
[probably 2000 lines] and messy header. It feels is very 'organic' and
doesn't seem very well planned out at all.

As I posted previously, I'd like to gather similar traits into their own
files. Martin didn't seem very keen on this idea because there was no
rationale for the proposed organization. There were no clear rules as to
what to name the headers and what should be included in each of them.

I'd love to create a rw/meta directory for all of the traits stuff.
Unfortunately this isn't a scheme that we use for any of the other
implementation files, so unless we can come up with an organization
policy, I'm thinking we should probably stick with what we're doing.


>Brad.
>

RE: type_traits progress

Posted by Eric Lemings <Er...@roguewave.com>.
 

> -----Original Message-----
> From: Travis Vitek [mailto:Travis.Vitek@roguewave.com] 
> Sent: Thursday, May 29, 2008 5:35 PM
> To: dev@stdcxx.apache.org
> Subject: RE: type_traits progress
> 
>  
> 
...
> 
>   rw/_meta_other.h
>     * __rw_enable_if
>     * __rw_conditional
> 
> What do you think of this?

Another possibility to consider is grouping them all in a subdir
of the include/rw directory; e.g., #include <rw/meta/_cv.h>.

I figure some C++0x components will need multiple header files
rather than one or two huge 100k files.  It might make sense for
such components to add a subdir within the include/rw directory.

Brad.

Re: type_traits progress

Posted by Martin Sebor <se...@roguewave.com>.
Travis Vitek wrote:
> 
> 
> Martin Sebor wrote:
>> Travis Vitek wrote:
>> [...]
>>>> Right. That could be another wrinkle. Our traits won't
>>>> work with generic code that takes integral_constant<T, V>
>>>> by reference.
>>> I don't really see the motivation, but it is obvious that the committee
>>> thought it was important for the standard traits to do so, so we should
>>> probably follow suit in our internal implementation.
> 
> I read the proposal for type traits and their motivation for using the base
> class integral_constant<T,V> is to avoid having to write out of line
> definitions as well as inline initialization of the static const member for
> every trait.
> 
> 
> Martin Sebor wrote:
>>> If we did decide to do this then we would probably want our own write
>>> __rw_integral_constant and use that internally to avoid namespace
>>> pollution? Then I'd assume we'd want something like the following
>>> example for is_const...
>> Yes, I think this is close to what we want. The only thing that bugs
>> me about it is...
>>
>>> template <class T, T v>
>>> struct __rw_integral_constant
>>> {
>>>   static const T value = v;
>>>   typedef T value_type;
>>>   typedef integral_constant<T,v> type;
>> ...this backward dependency on integral_constant, but I don't see how
>> to break it without template typedefs. I don't think there's a compiler
>> out there that supports them yet.
>>
>>> };
>>>
>>>
>>>>>> Another, and probably far more important reason for keeping the
>>>>>> names of the members the same, to make our implementation traits
>>>>>> look and feel like standard traits, i.e., conform to the traits
>>>>>> requirements. Otherwise the rest of our library won't be able
>>>>>> to easily use the private traits.
>>>>> But this should only be an issue if we are passing around traits as
>>>>> template parameters, right?
>>>> Right.
>>>>
>>>>> All of the scenerios I can think of we would be using 
>>>> __rw_enable_if or
>>>>> specialization on non-type template parameters. Can you think of any
>>>>> case where the name of the member would be important?
>>>> I searched the latest draft standard to see if traits were
>>>> being used anywhere in the spec but didn't get any hits.
>>>>
>>>> I hadn't thought too deeply about how the traits could be
>>>> used, but I have used traits outside of enable_if. I think
>>>> its should be easy to contrive code that wouldn't work with
>>>> our approach. Let me try:
>>>>
>>>>     // transforms T if it satisfies Property<T>
>>>>     // by applying Transformer<T>, otherwise leaves
>>>>     // T unchanged:
>>>>
>>>>     template <class T,
>>>>               template <class> Property,
>>>>               template <class> Transformer>
>>>>     struct TransformIf;
>>> Yes, if we go with the above approach then this problem just disappears
>>> for any trait inheriting from __rw_integral_constant. For the other
>>> types I can just expose the names that the standard defines.
>>>
>>> I'm okay with that if you think that the motivation is there.
>> I'm not sure the contrived example I gave qualifies as a motivating
>> use case but it is a use case nonetheless. That said, I don't think
>> consistency with other uglified names is a compelling enough reason
>> for us to dismiss even this contrived use case.
>>
> 
> As I mentioned in a previous message in this thread, I see no reason why the
> above wouldn't work with our current approach.
> 
>   template <class T,
>             template <class> Property,
>             template <class> Transformer>
>   struct __rw_transform_if
>   {
>       typedef typename
>       __rw_conditional<Property<T>::_C_value,
>                        T,
>                        Transformer<T>::_C_type>::_C_type _C_type;
>   };

It's been some time but I think my point was that TransformIf
was an example of a trait that couldn't interoperate with both
the standard and our own private traits.

> 
> Every one of the required traits have internal implementations, so any code
> that would be be written using required traits could be written using the
> internal ones. If the trait above was intended to be part of the
> implementation, then it would appear in the __rw namespace and it would use
> the internal traits. If it were intended to be part of the public interface,
> then it would be in the appropriate namespace and it would use the required
> traits.
> 
> So I don't see any motivation to use the same names as required by the
> standard for the internal types.

What is the motivation for using the name _C_type rather than
just type? The only reason we do it with other names is to avoid
clashes with user-defined macros but there can be no such macros
named type or value (not without clashing with the standard
traits).

> For the same reasons, I don't understand
> why integral_constant<T,V> should interit from __rw_integral_constant<T,V>.

I don't feel terribly strongly about this. If it turns out that
the derivation is important we can easily add it later.

Martin

Re: type_traits progress

Posted by Travis Vitek <vi...@roguewave.com>.


Martin Sebor wrote:
> 
> Travis Vitek wrote:
> [...]
>>> Right. That could be another wrinkle. Our traits won't
>>> work with generic code that takes integral_constant<T, V>
>>> by reference.
>> 
>> I don't really see the motivation, but it is obvious that the committee
>> thought it was important for the standard traits to do so, so we should
>> probably follow suit in our internal implementation.
> 

I read the proposal for type traits and their motivation for using the base
class integral_constant<T,V> is to avoid having to write out of line
definitions as well as inline initialization of the static const member for
every trait.


Martin Sebor wrote:
> 
>> 
>> If we did decide to do this then we would probably want our own write
>> __rw_integral_constant and use that internally to avoid namespace
>> pollution? Then I'd assume we'd want something like the following
>> example for is_const...
> 
> Yes, I think this is close to what we want. The only thing that bugs
> me about it is...
> 
>> 
>> template <class T, T v>
>> struct __rw_integral_constant
>> {
>>   static const T value = v;
>>   typedef T value_type;
>>   typedef integral_constant<T,v> type;
> 
> ...this backward dependency on integral_constant, but I don't see how
> to break it without template typedefs. I don't think there's a compiler
> out there that supports them yet.
> 
>> };
>> 
>> 
>>>>> Another, and probably far more important reason for keeping the
>>>>> names of the members the same, to make our implementation traits
>>>>> look and feel like standard traits, i.e., conform to the traits
>>>>> requirements. Otherwise the rest of our library won't be able
>>>>> to easily use the private traits.
>>>> But this should only be an issue if we are passing around traits as
>>>> template parameters, right?
>>> Right.
>>>
>>>> All of the scenerios I can think of we would be using 
>>> __rw_enable_if or
>>>> specialization on non-type template parameters. Can you think of any
>>>> case where the name of the member would be important?
>>> I searched the latest draft standard to see if traits were
>>> being used anywhere in the spec but didn't get any hits.
>>>
>>> I hadn't thought too deeply about how the traits could be
>>> used, but I have used traits outside of enable_if. I think
>>> its should be easy to contrive code that wouldn't work with
>>> our approach. Let me try:
>>>
>>>     // transforms T if it satisfies Property<T>
>>>     // by applying Transformer<T>, otherwise leaves
>>>     // T unchanged:
>>>
>>>     template <class T,
>>>               template <class> Property,
>>>               template <class> Transformer>
>>>     struct TransformIf;
>> 
>> Yes, if we go with the above approach then this problem just disappears
>> for any trait inheriting from __rw_integral_constant. For the other
>> types I can just expose the names that the standard defines.
>> 
>> I'm okay with that if you think that the motivation is there.
> 
> I'm not sure the contrived example I gave qualifies as a motivating
> use case but it is a use case nonetheless. That said, I don't think
> consistency with other uglified names is a compelling enough reason
> for us to dismiss even this contrived use case.
> 

As I mentioned in a previous message in this thread, I see no reason why the
above wouldn't work with our current approach.

  template <class T,
            template <class> Property,
            template <class> Transformer>
  struct __rw_transform_if
  {
      typedef typename
      __rw_conditional<Property<T>::_C_value,
                       T,
                       Transformer<T>::_C_type>::_C_type _C_type;
  };

Every one of the required traits have internal implementations, so any code
that would be be written using required traits could be written using the
internal ones. If the trait above was intended to be part of the
implementation, then it would appear in the __rw namespace and it would use
the internal traits. If it were intended to be part of the public interface,
then it would be in the appropriate namespace and it would use the required
traits.

So I don't see any motivation to use the same names as required by the
standard for the internal types. For the same reasons, I don't understand
why integral_constant<T,V> should interit from __rw_integral_constant<T,V>.

Travis
-- 
View this message in context: http://www.nabble.com/type_traits-progress-tp17442721p17788935.html
Sent from the stdcxx-dev mailing list archive at Nabble.com.


Re: type_traits progress

Posted by Martin Sebor <se...@roguewave.com>.
Travis Vitek wrote:
>  
> 
> Martin Sebor wrote:
>> Travis Vitek wrote:
>> [...]
>>>> Right. That could be another wrinkle. Our traits won't
>>>> work with generic code that takes integral_constant<T, V>
>>>> by reference.
>>> I don't really see the motivation, but it is obvious that 
>>> the committee thought it was important for the standard
>>> traits to do so, so we should probably follow suit in our
>>> internal implementation.
> 
> Can you think of a reason why this 'feature' would be important?

Derivation from integral_constant?

The original proposal explains the motivation for the base class:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2002/n1345.html

   There is one potential problem with integral constant members that
   should be raised: these require an out of line definition as well
   as an inline initialisation (but see issues 48 and 82). One
   implementation strategy that avoids the problem of having to provide
   lots of definitions for these static members, would be to have the
   traits classes inherit from a common base class:

   template <bool b> struct boolian_traits {
     static const bool value = b;
   };
   template <bool b> bool boolian_traits<b>::value;

   typedef boolian_traits<true> true_type;
   typedef boolian_traits<false> false_type;

   template <class T> struct is_void : public false_type {};
   template <> struct is_void<void> : public true_type {};

> 
>>> If we did decide to do this then we would probably want our own write
>>> __rw_integral_constant and use that internally to avoid namespace
>>> pollution? Then I'd assume we'd want something like the following
>>> example for is_const...
>> Yes, I think this is close to what we want. The only thing that bugs
>> me about it is...
>>
>>> template <class T, T v>
>>> struct __rw_integral_constant
>>> {
>>>   static const T value = v;
>>>   typedef T value_type;
>>>   typedef integral_constant<T,v> type;
>> ...this backward dependency on integral_constant, but I don't see how
>> to break it without template typedefs. I don't think there's a compiler
>> out there that supports them yet.
> 
> Actually, this was originally a typo on my part, but I do see where this
> is going. I haven't read about template typedefs, but it seems that
> there would be a serious problem caused by the cyclic dependency.

I don't know about serious but it does probably mean that we will
need to expose integral_constant among our private names and let
it "leak" into the std namespace wherever any of our private type
traits are used. Unless someone can come up with a way to avoid
it we might as well drop __rw_integral_constant and derive all
our private traits directly from integral_constant instead.


> 
>>> };
> 
>>>> I hadn't thought too deeply about how the traits could be
>>>> used, but I have used traits outside of enable_if. I think
>>>> its should be easy to contrive code that wouldn't work with
>>>> our approach. Let me try:
>>>>
>>>>     // transforms T if it satisfies Property<T>
>>>>     // by applying Transformer<T>, otherwise leaves
>>>>     // T unchanged:
>>>>
>>>>     template <class T,
>>>>               template <class> Property,
>>>>               template <class> Transformer>
>>>>     struct TransformIf;
>>> Yes, if we go with the above approach then this problem just 
>>> disappears for any trait inheriting from __rw_integral_constant.
>>> For the other types I can just expose the names that the standard
>>> defines.
>>>
>>> I'm okay with that if you think that the motivation is there.
>> I'm not sure the contrived example I gave qualifies as a motivating
>> use case but it is a use case nonetheless. That said, I don't think
>> consistency with other uglified names is a compelling enough reason
>> for us to dismiss even this contrived use case.
>>
> 
> I'm starting to think that the above example is not motivating at all.
> There is no reason that any of our library code would ever need to use
> the public types because those types are just alternate names for the
> internal implmentation types. If we are writing code to be used in other
> parts of our implementation, then we would always use the internal _C_
> names.

That's true for the standard traits, but not for user-defined ones.
Of course, that would only be an issue in the unlikely event that
we decided to expose an interface where users could supply their
own traits. Still, I don't see any benefit in avoiding the standard
names, value and type, in our private traits. We'll just end up with
more of these names in our implementation than there already are.

Martin

RE: type_traits progress

Posted by Travis Vitek <Tr...@roguewave.com>.
 

Martin Sebor worte:
>
>Eric Lemings wrote:
>>  
>> 
>> Martin Sebor wrote:
>>>
>>> Eric Lemings wrote:
>>>>  
>>>>
>>>>>>
>>>>>>> template <class T, T v>
>>>>>>> struct __rw_integral_constant
>>>>>>> {
>>>>>>>   static const T value = v;
>>>>>>>   typedef T value_type;
>>>>>>>   typedef integral_constant<T,v> type;
>>>>>>> }
>>>>
>>>> In all cases I've seen, `type' refers to type of self for identity
>>>> properties.  This typedef would not hold up the identity property.
>>> IIUC, for every specialization X of integral_constant, this
>>> must hold:
>>>
>>>    is_same<X, typename X::type>::value == true
>>>
>>> With integral_constant derived from __rw_integral_constant
>>> the condition would fail.
>> 
>> Not if it defined its own `type'.
>> 
>> 	template <class T, T v>
>> 	struct integral_constant: __rw_integral_constant<T, v>
>> 	{
>> 	  typedef integral_constant<T, v> type;
>> 	};
>
>Good point! This would effectively break the problematic dependency,
>wouldn't it, Travis?
>

Yes, it does allow us to use the name 'type' in both contexts.

>Martin
>

Re: type_traits progress

Posted by Martin Sebor <se...@roguewave.com>.
Eric Lemings wrote:
>  
> 
>> -----Original Message-----
>> From: Martin Sebor [mailto:sebor@roguewave.com] 
>> Sent: Monday, June 02, 2008 2:14 PM
>> To: dev@stdcxx.apache.org
>> Subject: Re: type_traits progress
>>
>> Eric Lemings wrote:
>>>  
>>>
>>>> -----Original Message-----
>>>> From: Travis Vitek [mailto:Travis.Vitek@roguewave.com] 
>>>> Sent: Friday, May 30, 2008 6:28 PM
>>>> To: dev@stdcxx.apache.org
>>>> Subject: RE: type_traits progress
>>>>
>>>>  
>>>>
>>>> Martin Sebor wrote:
>>>>> Travis Vitek wrote:
>>>>> [...]
>>>>>>> Right. That could be another wrinkle. Our traits won't
>>>>>>> work with generic code that takes integral_constant<T, V>
>>>>>>> by reference.
>>>>>> I don't really see the motivation, but it is obvious that 
>>>>>> the committee thought it was important for the standard
>>>>>> traits to do so, so we should probably follow suit in our
>>>>>> internal implementation.
>>>> Can you think of a reason why this 'feature' would be important?
>>>>
>>>>>> If we did decide to do this then we would probably want 
>>>> our own write
>>>>>> __rw_integral_constant and use that internally to avoid namespace
>>>>>> pollution? Then I'd assume we'd want something like the following
>>>>>> example for is_const...
>>>>> Yes, I think this is close to what we want. The only 
>> thing that bugs
>>>>> me about it is...
>>>>>
>>>>>> template <class T, T v>
>>>>>> struct __rw_integral_constant
>>>>>> {
>>>>>>   static const T value = v;
>>>>>>   typedef T value_type;
>>>>>>   typedef integral_constant<T,v> type;
>>>>> ...this backward dependency on integral_constant, but I 
>> don't see how
>>>>> to break it without template typedefs. I don't think there's 
>>>> a compiler
>>>>> out there that supports them yet.
>>>> Actually, this was originally a typo on my part, but I do see 
>>>> where this
>>>> is going. I haven't read about template typedefs, but it seems that
>>>> there would be a serious problem caused by the cyclic dependency.
>>> Yeah it looks like a typo to me too.  Should it be:
>>>
>>> 	typedef __rw_integral_constant<T,v> type;
>>>
>>> In all cases I've seen, `type' refers to type of self for identity
>>> properties.  This typedef would not hold up the identity property.
>> IIUC, for every specialization X of integral_constant, this
>> must hold:
>>
>>    is_same<X, typename X::type>::value == true
>>
>> With integral_constant derived from __rw_integral_constant
>> the condition would fail.
> 
> Not if it defined its own `type'.
> 
> 	template <class T, T v>
> 	struct integral_constant: __rw_integral_constant<T, v>
> 	{
> 	  typedef integral_constant<T, v> type;
> 	};

Good point! This would effectively break the problematic dependency,
wouldn't it, Travis?

Martin

RE: type_traits progress

Posted by Eric Lemings <Er...@roguewave.com>.
 

> -----Original Message-----
> From: Martin Sebor [mailto:sebor@roguewave.com] 
> Sent: Monday, June 02, 2008 2:14 PM
> To: dev@stdcxx.apache.org
> Subject: Re: type_traits progress
> 
> Eric Lemings wrote:
> >  
> > 
> >> -----Original Message-----
> >> From: Travis Vitek [mailto:Travis.Vitek@roguewave.com] 
> >> Sent: Friday, May 30, 2008 6:28 PM
> >> To: dev@stdcxx.apache.org
> >> Subject: RE: type_traits progress
> >>
> >>  
> >>
> >> Martin Sebor wrote:
> >>> Travis Vitek wrote:
> >>> [...]
> >>>>> Right. That could be another wrinkle. Our traits won't
> >>>>> work with generic code that takes integral_constant<T, V>
> >>>>> by reference.
> >>>> I don't really see the motivation, but it is obvious that 
> >>>> the committee thought it was important for the standard
> >>>> traits to do so, so we should probably follow suit in our
> >>>> internal implementation.
> >> Can you think of a reason why this 'feature' would be important?
> >>
> >>>> If we did decide to do this then we would probably want 
> >> our own write
> >>>> __rw_integral_constant and use that internally to avoid namespace
> >>>> pollution? Then I'd assume we'd want something like the following
> >>>> example for is_const...
> >>> Yes, I think this is close to what we want. The only 
> thing that bugs
> >>> me about it is...
> >>>
> >>>> template <class T, T v>
> >>>> struct __rw_integral_constant
> >>>> {
> >>>>   static const T value = v;
> >>>>   typedef T value_type;
> >>>>   typedef integral_constant<T,v> type;
> >>> ...this backward dependency on integral_constant, but I 
> don't see how
> >>> to break it without template typedefs. I don't think there's 
> >> a compiler
> >>> out there that supports them yet.
> >> Actually, this was originally a typo on my part, but I do see 
> >> where this
> >> is going. I haven't read about template typedefs, but it seems that
> >> there would be a serious problem caused by the cyclic dependency.
> > 
> > Yeah it looks like a typo to me too.  Should it be:
> > 
> > 	typedef __rw_integral_constant<T,v> type;
> > 
> > In all cases I've seen, `type' refers to type of self for identity
> > properties.  This typedef would not hold up the identity property.
> 
> IIUC, for every specialization X of integral_constant, this
> must hold:
> 
>    is_same<X, typename X::type>::value == true
> 
> With integral_constant derived from __rw_integral_constant
> the condition would fail.

Not if it defined its own `type'.

	template <class T, T v>
	struct integral_constant: __rw_integral_constant<T, v>
	{
	  typedef integral_constant<T, v> type;
	};

That's the way I usually see it done.

Brad.

Re: type_traits progress

Posted by Martin Sebor <se...@roguewave.com>.
Eric Lemings wrote:
>  
> 
>> -----Original Message-----
>> From: Travis Vitek [mailto:Travis.Vitek@roguewave.com] 
>> Sent: Friday, May 30, 2008 6:28 PM
>> To: dev@stdcxx.apache.org
>> Subject: RE: type_traits progress
>>
>>  
>>
>> Martin Sebor wrote:
>>> Travis Vitek wrote:
>>> [...]
>>>>> Right. That could be another wrinkle. Our traits won't
>>>>> work with generic code that takes integral_constant<T, V>
>>>>> by reference.
>>>> I don't really see the motivation, but it is obvious that 
>>>> the committee thought it was important for the standard
>>>> traits to do so, so we should probably follow suit in our
>>>> internal implementation.
>> Can you think of a reason why this 'feature' would be important?
>>
>>>> If we did decide to do this then we would probably want 
>> our own write
>>>> __rw_integral_constant and use that internally to avoid namespace
>>>> pollution? Then I'd assume we'd want something like the following
>>>> example for is_const...
>>> Yes, I think this is close to what we want. The only thing that bugs
>>> me about it is...
>>>
>>>> template <class T, T v>
>>>> struct __rw_integral_constant
>>>> {
>>>>   static const T value = v;
>>>>   typedef T value_type;
>>>>   typedef integral_constant<T,v> type;
>>> ...this backward dependency on integral_constant, but I don't see how
>>> to break it without template typedefs. I don't think there's 
>> a compiler
>>> out there that supports them yet.
>> Actually, this was originally a typo on my part, but I do see 
>> where this
>> is going. I haven't read about template typedefs, but it seems that
>> there would be a serious problem caused by the cyclic dependency.
> 
> Yeah it looks like a typo to me too.  Should it be:
> 
> 	typedef __rw_integral_constant<T,v> type;
> 
> In all cases I've seen, `type' refers to type of self for identity
> properties.  This typedef would not hold up the identity property.

IIUC, for every specialization X of integral_constant, this
must hold:

   is_same<X, typename X::type>::value == true

With integral_constant derived from __rw_integral_constant
the condition would fail.

Martin


RE: type_traits progress

Posted by Eric Lemings <Er...@roguewave.com>.
 

> -----Original Message-----
> From: Travis Vitek [mailto:Travis.Vitek@roguewave.com] 
> Sent: Friday, May 30, 2008 6:28 PM
> To: dev@stdcxx.apache.org
> Subject: RE: type_traits progress
> 
>  
> 
> Martin Sebor wrote:
> >Travis Vitek wrote:
> >[...]
> >>> Right. That could be another wrinkle. Our traits won't
> >>> work with generic code that takes integral_constant<T, V>
> >>> by reference.
> >> 
> >> I don't really see the motivation, but it is obvious that 
> >> the committee thought it was important for the standard
> >> traits to do so, so we should probably follow suit in our
> >> internal implementation.
> 
> Can you think of a reason why this 'feature' would be important?
> 
> >> 
> >> If we did decide to do this then we would probably want 
> our own write
> >> __rw_integral_constant and use that internally to avoid namespace
> >> pollution? Then I'd assume we'd want something like the following
> >> example for is_const...
> >
> >Yes, I think this is close to what we want. The only thing that bugs
> >me about it is...
> >
> >> 
> >> template <class T, T v>
> >> struct __rw_integral_constant
> >> {
> >>   static const T value = v;
> >>   typedef T value_type;
> >>   typedef integral_constant<T,v> type;
> >
> >...this backward dependency on integral_constant, but I don't see how
> >to break it without template typedefs. I don't think there's 
> a compiler
> >out there that supports them yet.
> 
> Actually, this was originally a typo on my part, but I do see 
> where this
> is going. I haven't read about template typedefs, but it seems that
> there would be a serious problem caused by the cyclic dependency.

Yeah it looks like a typo to me too.  Should it be:

	typedef __rw_integral_constant<T,v> type;

In all cases I've seen, `type' refers to type of self for identity
properties.  This typedef would not hold up the identity property.

Brad.

RE: type_traits progress

Posted by Travis Vitek <Tr...@roguewave.com>.
 

Martin Sebor wrote:
>Travis Vitek wrote:
>[...]
>>> Right. That could be another wrinkle. Our traits won't
>>> work with generic code that takes integral_constant<T, V>
>>> by reference.
>> 
>> I don't really see the motivation, but it is obvious that 
>> the committee thought it was important for the standard
>> traits to do so, so we should probably follow suit in our
>> internal implementation.

Can you think of a reason why this 'feature' would be important?

>> 
>> If we did decide to do this then we would probably want our own write
>> __rw_integral_constant and use that internally to avoid namespace
>> pollution? Then I'd assume we'd want something like the following
>> example for is_const...
>
>Yes, I think this is close to what we want. The only thing that bugs
>me about it is...
>
>> 
>> template <class T, T v>
>> struct __rw_integral_constant
>> {
>>   static const T value = v;
>>   typedef T value_type;
>>   typedef integral_constant<T,v> type;
>
>...this backward dependency on integral_constant, but I don't see how
>to break it without template typedefs. I don't think there's a compiler
>out there that supports them yet.

Actually, this was originally a typo on my part, but I do see where this
is going. I haven't read about template typedefs, but it seems that
there would be a serious problem caused by the cyclic dependency.

>> };

>>> I hadn't thought too deeply about how the traits could be
>>> used, but I have used traits outside of enable_if. I think
>>> its should be easy to contrive code that wouldn't work with
>>> our approach. Let me try:
>>>
>>>     // transforms T if it satisfies Property<T>
>>>     // by applying Transformer<T>, otherwise leaves
>>>     // T unchanged:
>>>
>>>     template <class T,
>>>               template <class> Property,
>>>               template <class> Transformer>
>>>     struct TransformIf;
>> 
>> Yes, if we go with the above approach then this problem just 
>> disappears for any trait inheriting from __rw_integral_constant.
>> For the other types I can just expose the names that the standard
>> defines.
>> 
>> I'm okay with that if you think that the motivation is there.
>
>I'm not sure the contrived example I gave qualifies as a motivating
>use case but it is a use case nonetheless. That said, I don't think
>consistency with other uglified names is a compelling enough reason
>for us to dismiss even this contrived use case.
>

I'm starting to think that the above example is not motivating at all.
There is no reason that any of our library code would ever need to use
the public types because those types are just alternate names for the
internal implmentation types. If we are writing code to be used in other
parts of our implementation, then we would always use the internal _C_
names.

>Martin
>

Re: type_traits progress

Posted by Martin Sebor <se...@roguewave.com>.
Travis Vitek wrote:
[...]
>> Right. That could be another wrinkle. Our traits won't
>> work with generic code that takes integral_constant<T, V>
>> by reference.
> 
> I don't really see the motivation, but it is obvious that the committee
> thought it was important for the standard traits to do so, so we should
> probably follow suit in our internal implementation.
> 
> If we did decide to do this then we would probably want our own write
> __rw_integral_constant and use that internally to avoid namespace
> pollution? Then I'd assume we'd want something like the following
> example for is_const...

Yes, I think this is close to what we want. The only thing that bugs
me about it is...

> 
> template <class T, T v>
> struct __rw_integral_constant
> {
>   static const T value = v;
>   typedef T value_type;
>   typedef integral_constant<T,v> type;

...this backward dependency on integral_constant, but I don't see how
to break it without template typedefs. I don't think there's a compiler
out there that supports them yet.

> };
> 
> template <class T>
> struct __rw_is_const_impl
> {
>   enum { _C_value = 0 };
> };
> 
> template <class T>
> struct __rw_is_const_impl<const T>
> {
>   enum { _C_value = 1 };
> };
> 
> template <class T>
> struct __rw_is_const
>   : __rw_integral_constant<bool, __rw_is_const_impl<T>::_C_value>
> {
> };
> 
> template <class T, T v>
> struct integral_constant : __rw_integral_constant<T,v>
> {
> };
> 
> template <class T>
> struct is_const : integral_constant<bool, __rw_is_const<T>::value>
> {
> };
> 
>>>> Another, and probably far more important reason for keeping the
>>>> names of the members the same, to make our implementation traits
>>>> look and feel like standard traits, i.e., conform to the traits
>>>> requirements. Otherwise the rest of our library won't be able
>>>> to easily use the private traits.
>>> But this should only be an issue if we are passing around traits as
>>> template parameters, right?
>> Right.
>>
>>> All of the scenerios I can think of we would be using 
>> __rw_enable_if or
>>> specialization on non-type template parameters. Can you think of any
>>> case where the name of the member would be important?
>> I searched the latest draft standard to see if traits were
>> being used anywhere in the spec but didn't get any hits.
>>
>> I hadn't thought too deeply about how the traits could be
>> used, but I have used traits outside of enable_if. I think
>> its should be easy to contrive code that wouldn't work with
>> our approach. Let me try:
>>
>>     // transforms T if it satisfies Property<T>
>>     // by applying Transformer<T>, otherwise leaves
>>     // T unchanged:
>>
>>     template <class T,
>>               template <class> Property,
>>               template <class> Transformer>
>>     struct TransformIf;
> 
> Yes, if we go with the above approach then this problem just disappears
> for any trait inheriting from __rw_integral_constant. For the other
> types I can just expose the names that the standard defines.
> 
> I'm okay with that if you think that the motivation is there.

I'm not sure the contrived example I gave qualifies as a motivating
use case but it is a use case nonetheless. That said, I don't think
consistency with other uglified names is a compelling enough reason
for us to dismiss even this contrived use case.

Martin

RE: type_traits progress

Posted by Eric Lemings <Er...@roguewave.com>.
 

> -----Original Message-----
> From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin Sebor
> Sent: Saturday, May 31, 2008 3:42 PM
> To: dev@stdcxx.apache.org
> Subject: Re: type_traits progress
> 
...
> 
> The problem with metaprogramming is that many compilers weren't
> designed for the kind of involved computation that some of these
> algorithms require, so their performance really blows. It's a
> fun exercise to time the compilation of a non-trivial metaprogram
> (e.g., sorting a typelist) while watching its memory consumption.

Yeah I've actually written code that does that: part of a Boost
library proposal a couple years back.  As I recall, it took me a
week to figure out how to make it work.

Brad.

Re: type_traits progress

Posted by Martin Sebor <se...@roguewave.com>.
Eric Lemings wrote:
>  
> 
>> -----Original Message-----
>> From: Martin Sebor [mailto:sebor@roguewave.com] 
>> Sent: Friday, May 30, 2008 3:05 PM
>> To: dev@stdcxx.apache.org
>> Subject: Re: type_traits progress
>>
>> Travis Vitek wrote:
>>>  
>>>
>>> Eric Lemings wrote:
>>>>> Travis Vitek wrote:
>>>>>  
>>>> ...
>>>>> As an example, the array traits above are all closely related 
>>>>> and their
>>>>> implementations are similar. There are five traits, and 
>> those traits
>>>>> span three sections of the standard.
>>>>>
>>>>> I'm open to doing some type of grouping, we just need to 
>>>>> understand how
>>>>> we want to group them and then how we want to name the files.
>>>> The term you're looking for is cohesion.  :)  I kinda like this
>>>> organization.  Couple things though.
>>>>
>>>> Why put __rw_decay, a single helper trait in its own header?
>>> Well decay deals with conversion from array to pointer and 
>> function to
>>> function pointer conversions. I can't necessarily put it into both
>>> _meta_array.h and _meta_func.h, so I figured it would be 
>> best to put it
>>> into a file by itself.
>> FWIW, I see no problem with bundling groups of traits together
>> even if some of them are unlikely to be used in the rest of the
>> lib, just as long as their implementation isn't too big (i.e.,
>> doesn't bloat translation units and unnecessarily increase
>> compilation time).
> 
> Well when it comes to metaprogramming, there's almost always a
> tradeoff in these two respects.  Either the translation unit
> size increases or compile times increase.

They tend to go hand in hand. But you probably meant the size
of the generated object code.

> But you're right:
> we should minimize both whenever possible.
> 
> BTW, which of these two should be the preferred: comile-time
> computations (metaprogramming) or runtime processing?  I would
> say compile-time even though that will signficantly impact us
> developers but I think users would prefer this since they do
> not build nearly as often.

I'm sure you're right in the majority of cases. But as John Lakos
writes in his Large-Scale C++ Software Design compilation time is
exceedingly important for large code bases with millions of lines
of code: http://www.amazon.com/dp/0201633620

The problem with metaprogramming is that many compilers weren't
designed for the kind of involved computation that some of these
algorithms require, so their performance really blows. It's a
fun exercise to time the compilation of a non-trivial metaprogram
(e.g., sorting a typelist) while watching its memory consumption.

Martin

RE: type_traits progress

Posted by Eric Lemings <Er...@roguewave.com>.
 

> -----Original Message-----
> From: Martin Sebor [mailto:sebor@roguewave.com] 
> Sent: Friday, May 30, 2008 3:05 PM
> To: dev@stdcxx.apache.org
> Subject: Re: type_traits progress
> 
> Travis Vitek wrote:
> >  
> > 
> > Eric Lemings wrote:
> >>> Travis Vitek wrote:
> >>>  
> >> ...
> >>> As an example, the array traits above are all closely related 
> >>> and their
> >>> implementations are similar. There are five traits, and 
> those traits
> >>> span three sections of the standard.
> >>>
> >>> I'm open to doing some type of grouping, we just need to 
> >>> understand how
> >>> we want to group them and then how we want to name the files.
> >> The term you're looking for is cohesion.  :)  I kinda like this
> >> organization.  Couple things though.
> >>
> >> Why put __rw_decay, a single helper trait in its own header?
> > 
> > Well decay deals with conversion from array to pointer and 
> function to
> > function pointer conversions. I can't necessarily put it into both
> > _meta_array.h and _meta_func.h, so I figured it would be 
> best to put it
> > into a file by itself.
> 
> FWIW, I see no problem with bundling groups of traits together
> even if some of them are unlikely to be used in the rest of the
> lib, just as long as their implementation isn't too big (i.e.,
> doesn't bloat translation units and unnecessarily increase
> compilation time).

Well when it comes to metaprogramming, there's almost always a
tradeoff in these two respects.  Either the translation unit
size increases or compile times increase.  But you're right:
we should minimize both whenever possible.

BTW, which of these two should be the preferred: comile-time
computations (metaprogramming) or runtime processing?  I would
say compile-time even though that will signficantly impact us
developers but I think users would prefer this since they do
not build nearly as often.

Brad.

Re: type_traits progress

Posted by Martin Sebor <se...@roguewave.com>.
Travis Vitek wrote:
>  
> 
> Eric Lemings wrote:
>>> Travis Vitek wrote:
>>>  
>> ...
>>> As an example, the array traits above are all closely related 
>>> and their
>>> implementations are similar. There are five traits, and those traits
>>> span three sections of the standard.
>>>
>>> I'm open to doing some type of grouping, we just need to 
>>> understand how
>>> we want to group them and then how we want to name the files.
>> The term you're looking for is cohesion.  :)  I kinda like this
>> organization.  Couple things though.
>>
>> Why put __rw_decay, a single helper trait in its own header?
> 
> Well decay deals with conversion from array to pointer and function to
> function pointer conversions. I can't necessarily put it into both
> _meta_array.h and _meta_func.h, so I figured it would be best to put it
> into a file by itself.

FWIW, I see no problem with bundling groups of traits together
even if some of them are unlikely to be used in the rest of the
lib, just as long as their implementation isn't too big (i.e.,
doesn't bloat translation units and unnecessarily increase
compilation time).

Martin

> 
>> Also I would use the filename rw/_meta_util.h rather than
>> rw/_meta_other.h but that's just me.  :)
> 
> Yeah, I could do that.
> 
>> Brad.
>>


RE: type_traits progress

Posted by Travis Vitek <Tr...@roguewave.com>.
 

Eric Lemings wrote:
>
>> Travis Vitek wrote:
>>  
>...
>> 
>> As an example, the array traits above are all closely related 
>> and their
>> implementations are similar. There are five traits, and those traits
>> span three sections of the standard.
>> 
>> I'm open to doing some type of grouping, we just need to 
>> understand how
>> we want to group them and then how we want to name the files.
>
>The term you're looking for is cohesion.  :)  I kinda like this
>organization.  Couple things though.
>
>Why put __rw_decay, a single helper trait in its own header?

Well decay deals with conversion from array to pointer and function to
function pointer conversions. I can't necessarily put it into both
_meta_array.h and _meta_func.h, so I figured it would be best to put it
into a file by itself.

>Also I would use the filename rw/_meta_util.h rather than
>rw/_meta_other.h but that's just me.  :)

Yeah, I could do that.

>
>Brad.
>

RE: type_traits progress

Posted by Eric Lemings <Er...@roguewave.com>.
 

> -----Original Message-----
> From: Travis Vitek [mailto:Travis.Vitek@roguewave.com] 
> Sent: Friday, May 30, 2008 12:40 PM
> To: dev@stdcxx.apache.org
> Subject: RE: type_traits progress
> 
>  
...
> 
> As an example, the array traits above are all closely related 
> and their
> implementations are similar. There are five traits, and those traits
> span three sections of the standard.
> 
> I'm open to doing some type of grouping, we just need to 
> understand how
> we want to group them and then how we want to name the files.

The term you're looking for is cohesion.  :)  I kinda like this
organization.  Couple things though.

Why put __rw_decay, a single helper trait in its own header?

Also I would use the filename rw/_meta_util.h rather than
rw/_meta_other.h but that's just me.  :)

Brad.

Re: type_traits progress

Posted by Martin Sebor <se...@roguewave.com>.
Travis Vitek wrote:
>  
> 
> Martin Sebor wrote:
>> Travis Vitek wrote:
>>>  
>> [...]
>>>> On a related note, I wonder if it would make sense to consolidate
>>>> some of the implementation headers that we don't expect to be useful
>>>> in the rest of the library on their own (e.g., all the ctor
>>>> headers/traits).
>>> I think it would. I'd like to consolidate these a little further. I'd
>>> like to either put them in headers by category, something like this
>>> [those not mentioned would go into their own header].
>> My initial thought was to group them based on how they are
>> likely to be used in the rest of the library. Another option
>> would be to follow the breakdown used by the standard. Your
>> organization doesn't seem to fall into either of these two
>> categories. What was your rationale for it?
> 
> I'm just grouping closely related traits.
> 
>>>   rw/_meta_arr.h
>>>     * __rw_rank
>>>     * __rw_extent
>>>     * __rw_is_array
>>>     * __rw_remove_extent
>>>     * __rw_remove_all_extents
> 
> As an example, the array traits above are all closely related and their
> implementations are similar. There are five traits, and those traits
> span three sections of the standard.
> 
> I'm open to doing some type of grouping, we just need to understand how
> we want to group them and then how we want to name the files.

Like I said, the most useful grouping I see is keeping together
those traits that are likely to be used together in the rest of
the library. I expect us to make heavy use of type traits in
containers and their supporting algorithms to optimize away
unnecessary initialization, explicit destruction, and exception
handling.

 From this POV, containers will most likely need the is/has_trivial
family of traits, along with has_nothrow_xxx, and __rw_enable_if
and maybe also __rw_conditional. I'd like us to be able to bring
these into scope without dragging in all the others. The ones
that we won't use in the rest of the library might just as well
be in the same header (such as <type_traits>) as far as I'm
concerned.

Martin

RE: type_traits progress

Posted by Travis Vitek <Tr...@roguewave.com>.
 

Martin Sebor wrote:
>
>Travis Vitek wrote:
>>  
>[...]
>>> On a related note, I wonder if it would make sense to consolidate
>>> some of the implementation headers that we don't expect to be useful
>>> in the rest of the library on their own (e.g., all the ctor
>>> headers/traits).
>> 
>> I think it would. I'd like to consolidate these a little further. I'd
>> like to either put them in headers by category, something like this
>> [those not mentioned would go into their own header].
>
>My initial thought was to group them based on how they are
>likely to be used in the rest of the library. Another option
>would be to follow the breakdown used by the standard. Your
>organization doesn't seem to fall into either of these two
>categories. What was your rationale for it?

I'm just grouping closely related traits.

>>   rw/_meta_arr.h
>>     * __rw_rank
>>     * __rw_extent
>>     * __rw_is_array
>>     * __rw_remove_extent
>>     * __rw_remove_all_extents

As an example, the array traits above are all closely related and their
implementations are similar. There are five traits, and those traits
span three sections of the standard.

I'm open to doing some type of grouping, we just need to understand how
we want to group them and then how we want to name the files.

>> 
>>>>
>>>>>  *  Do the trait member (e.g., _C_type, _C_value) need to be
>>>>>     privatized or would it make more sense to use the 
>>>>>     required names?
>>>> I'm not sure what you're saying here. The types in the 
>>>> public interface all have the required names [from the
>>>> base integral_constant template].
>>>>
>>>> Everything else is an internal class, and I thought that we always
>>>> needed to use privatized names for internal classes exposed in the
>>>> headers. Using names consistent with those in the public interface
>>>> doesn't buy us anything significant that I can think of, and 
>>>> there is no requirement that I know of saying we should.
>> 
>> [snip]
>> 
>>> One reason why I asked the question was that if we derived the
>>> standard traits from the implementation-defined ones we wouldn't
>>> need to re-declare these members. (I now see that we don't use
>>> derivation).
>> 
>> We're not allowed to. In all cases the public type is required to to
>> inherit 'directly or indirectly' from integral_constant<T,V>.
>
>Right. That could be another wrinkle. Our traits won't
>work with generic code that takes integral_constant<T, V>
>by reference.

I don't really see the motivation, but it is obvious that the committee
thought it was important for the standard traits to do so, so we should
probably follow suit in our internal implementation.

If we did decide to do this then we would probably want our own write
__rw_integral_constant and use that internally to avoid namespace
pollution? Then I'd assume we'd want something like the following
example for is_const...

template <class T, T v>
struct __rw_integral_constant
{
  static const T value = v;
  typedef T value_type;
  typedef integral_constant<T,v> type;
};

template <class T>
struct __rw_is_const_impl
{
  enum { _C_value = 0 };
};

template <class T>
struct __rw_is_const_impl<const T>
{
  enum { _C_value = 1 };
};

template <class T>
struct __rw_is_const
  : __rw_integral_constant<bool, __rw_is_const_impl<T>::_C_value>
{
};

template <class T, T v>
struct integral_constant : __rw_integral_constant<T,v>
{
};

template <class T>
struct is_const : integral_constant<bool, __rw_is_const<T>::value>
{
};

>> 
>>> Another, and probably far more important reason for keeping the
>>> names of the members the same, to make our implementation traits
>>> look and feel like standard traits, i.e., conform to the traits
>>> requirements. Otherwise the rest of our library won't be able
>>> to easily use the private traits.
>> 
>> But this should only be an issue if we are passing around traits as
>> template parameters, right?
>
>Right.
>
>> 
>> All of the scenerios I can think of we would be using 
>__rw_enable_if or
>> specialization on non-type template parameters. Can you think of any
>> case where the name of the member would be important?
>
>I searched the latest draft standard to see if traits were
>being used anywhere in the spec but didn't get any hits.
>
>I hadn't thought too deeply about how the traits could be
>used, but I have used traits outside of enable_if. I think
>its should be easy to contrive code that wouldn't work with
>our approach. Let me try:
>
>     // transforms T if it satisfies Property<T>
>     // by applying Transformer<T>, otherwise leaves
>     // T unchanged:
>
>     template <class T,
>               template <class> Property,
>               template <class> Transformer>
>     struct TransformIf;

Yes, if we go with the above approach then this problem just disappears
for any trait inheriting from __rw_integral_constant. For the other
types I can just expose the names that the standard defines.

I'm okay with that if you think that the motivation is there.

>
>Martin
>

Re: type_traits progress

Posted by Martin Sebor <se...@roguewave.com>.
Travis Vitek wrote:
>  
[...]
>> On a related note, I wonder if it would make sense to consolidate
>> some of the implementation headers that we don't expect to be useful
>> in the rest of the library on their own (e.g., all the ctor
>> headers/traits).
> 
> I think it would. I'd like to consolidate these a little further. I'd
> like to either put them in headers by category, something like this
> [those not mentioned would go into their own header].

My initial thought was to group them based on how they are
likely to be used in the rest of the library. Another option
would be to follow the breakdown used by the standard. Your
organization doesn't seem to fall into either of these two
categories. What was your rationale for it?

> 
>   rw/_meta_cv.h
>     * __rw_add_const
>     * __rw_add_volatile
>     * __rw_add_cv
>     * __rw_is_const
>     * __rw_is_volatile
>     * __rw_remove_const
>     * __rw_remove_volatile
>     * __rw_remove_cv
> 
>   rw/_meta_trivial.h
>     * __rw_is_trivial
>     * __rw_has_trivial_ctor
>     * __rw_has_trivial_copy
>     * __rw_has_trivial_assign
>     * __rw_has_trivial_dtor
> 
>   rw/_meta_nothrow.h
>     * __rw_has_nothrow_ctor
>     * __rw_has_nothrow_copy
>     * __rw_has_nothrow_assign
>     * __rw_has_nothrow_dtor
> 
>   rw/_meta_sign.h
>     * __rw_is_signed
>     * __rw_is_unsigned
>     * __rw_make_signed
>     * __rw_make_unsigned
> 
>   rw/_meta_arr.h
>     * __rw_rank
>     * __rw_extent
>     * __rw_is_array
>     * __rw_remove_extent
>     * __rw_remove_all_extents
> 
>   rw/_meta_ptr.h
>     * __rw_add_pointer
>     * __rw_remove_pointer
>     * __rw_is_pointer
> 
>   rw/_meta_ref.h
>     * __rw_is_lval_ref
>     * __rw_is_rval_ref
>     * __rw_is_ref
>     * __rw_add_lval_ref
>     * __rw_add_rval_ref
> 
>   rw/_meta_member.h
>     * __rw_is_mem_ptr
>     * __rw_is_mem_obj_ptr
>     * __rw_is_mem_fun_ptr
> 
>   rw/_meta_align.h
>     * __rw_aligned_storage
>     * __rw_aligned_union
> 
>   rw/_meta_decay.h
>     * __rw_decay
> 
>   rw/_meta_other.h
>     * __rw_enable_if
>     * __rw_conditional
> 
> What do you think of this?
> 
>>>
>>>>  *  Do the trait member (e.g., _C_type, _C_value) need to be
>>>>     privatized or would it make more sense to use the 
>>>>     required names?
>>> I'm not sure what you're saying here. The types in the 
>>> public interface all have the required names [from the
>>> base integral_constant template].
>>>
>>> Everything else is an internal class, and I thought that we always
>>> needed to use privatized names for internal classes exposed in the
>>> headers. Using names consistent with those in the public interface
>>> doesn't buy us anything significant that I can think of, and 
>>> there is no requirement that I know of saying we should.
> 
> [snip]
> 
>> One reason why I asked the question was that if we derived the
>> standard traits from the implementation-defined ones we wouldn't
>> need to re-declare these members. (I now see that we don't use
>> derivation).
> 
> We're not allowed to. In all cases the public type is required to to
> inherit 'directly or indirectly' from integral_constant<T,V>.

Right. That could be another wrinkle. Our traits won't
work with generic code that takes integral_constant<T, V>
by reference.

> 
>> Another, and probably far more important reason for keeping the
>> names of the members the same, to make our implementation traits
>> look and feel like standard traits, i.e., conform to the traits
>> requirements. Otherwise the rest of our library won't be able
>> to easily use the private traits.
> 
> But this should only be an issue if we are passing around traits as
> template parameters, right?

Right.

> 
> All of the scenerios I can think of we would be using __rw_enable_if or
> specialization on non-type template parameters. Can you think of any
> case where the name of the member would be important?

I searched the latest draft standard to see if traits were
being used anywhere in the spec but didn't get any hits.

I hadn't thought too deeply about how the traits could be
used, but I have used traits outside of enable_if. I think
its should be easy to contrive code that wouldn't work with
our approach. Let me try:

     // transforms T if it satisfies Property<T>
     // by applying Transformer<T>, otherwise leaves
     // T unchanged:

     template <class T,
               template <class> Property,
               template <class> Transformer>
     struct TransformIf;

Martin

RE: type_traits progress

Posted by Travis Vitek <Tr...@roguewave.com>.
 

>Martin Sebor wrote:
>
>Travis Vitek wrote:
>>  
>> 
>> 
>> If this is the case I may opt to merge the headers. i.e. _rw_has.h
>
>I'd get rid of the _rw prefix and abbreviate the names.

My example was flawed. None of the header names begin with the _rw
prefix.

>E.g., use
>"ctor" instead of "constructor" etc. In fact, I wouldn't be at all
>upset if we abbreviated the names of some the private traits as
>well, e.g., truncate __rw_add_lvalue_reference to __rw_add_lval_ref
>or something similar). Not just to spare us the typing a few extra
>characters but also to reduce the sizes of symbol tables generated
>for specializations involving these critters (FYI: this was bad
>enough in C++ 98 that the IA64 ABI put in special cases for the
>most egregious symbols: std::string and std::wstring).
>

I'm all for cutting down the length of the names of the internal
classes. I'll do this in the next pass.

>On a related note, I wonder if it would make sense to consolidate
>some of the implementation headers that we don't expect to be useful
>in the rest of the library on their own (e.g., all the ctor
>headers/traits).

I think it would. I'd like to consolidate these a little further. I'd
like to either put them in headers by category, something like this
[those not mentioned would go into their own header].

  rw/_meta_cv.h
    * __rw_add_const
    * __rw_add_volatile
    * __rw_add_cv
    * __rw_is_const
    * __rw_is_volatile
    * __rw_remove_const
    * __rw_remove_volatile
    * __rw_remove_cv

  rw/_meta_trivial.h
    * __rw_is_trivial
    * __rw_has_trivial_ctor
    * __rw_has_trivial_copy
    * __rw_has_trivial_assign
    * __rw_has_trivial_dtor

  rw/_meta_nothrow.h
    * __rw_has_nothrow_ctor
    * __rw_has_nothrow_copy
    * __rw_has_nothrow_assign
    * __rw_has_nothrow_dtor

  rw/_meta_sign.h
    * __rw_is_signed
    * __rw_is_unsigned
    * __rw_make_signed
    * __rw_make_unsigned

  rw/_meta_arr.h
    * __rw_rank
    * __rw_extent
    * __rw_is_array
    * __rw_remove_extent
    * __rw_remove_all_extents

  rw/_meta_ptr.h
    * __rw_add_pointer
    * __rw_remove_pointer
    * __rw_is_pointer

  rw/_meta_ref.h
    * __rw_is_lval_ref
    * __rw_is_rval_ref
    * __rw_is_ref
    * __rw_add_lval_ref
    * __rw_add_rval_ref

  rw/_meta_member.h
    * __rw_is_mem_ptr
    * __rw_is_mem_obj_ptr
    * __rw_is_mem_fun_ptr

  rw/_meta_align.h
    * __rw_aligned_storage
    * __rw_aligned_union

  rw/_meta_decay.h
    * __rw_decay

  rw/_meta_other.h
    * __rw_enable_if
    * __rw_conditional

What do you think of this?

>
>> 
>> 
>>>  *  Do the trait member (e.g., _C_type, _C_value) need to be
>>>     privatized or would it make more sense to use the 
>>>     required names?
>> 
>> I'm not sure what you're saying here. The types in the 
>> public interface all have the required names [from the
>> base integral_constant template].
>> 
>> Everything else is an internal class, and I thought that we always
>> needed to use privatized names for internal classes exposed in the
>> headers. Using names consistent with those in the public interface
>> doesn't buy us anything significant that I can think of, and 
>> there is no requirement that I know of saying we should.
>

[snip]

>
>One reason why I asked the question was that if we derived the
>standard traits from the implementation-defined ones we wouldn't
>need to re-declare these members. (I now see that we don't use
>derivation).

We're not allowed to. In all cases the public type is required to to
inherit 'directly or indirectly' from integral_constant<T,V>.

>Another, and probably far more important reason for keeping the
>names of the members the same, to make our implementation traits
>look and feel like standard traits, i.e., conform to the traits
>requirements. Otherwise the rest of our library won't be able
>to easily use the private traits.

But this should only be an issue if we are passing around traits as
template parameters, right?

All of the scenerios I can think of we would be using __rw_enable_if or
specialization on non-type template parameters. Can you think of any
case where the name of the member would be important?

Travis

Re: type_traits progress

Posted by Martin Sebor <se...@roguewave.com>.
Travis Vitek wrote:
>  
> 
[...]
>> Regarding naming:
>>
>>  *  File names should be abbreviated so as not to exceed the 14
>>     character minimum required by POSIX.
> 
> I wasn't aware of a 14 character limit, and I'm guessing that this is to
> do with the length of the header name as we don't limit the length of
> the test names or config test names in any way.

The test names don't matter as much as those of the library headers
because the worst that can happen is with the tests that the they
won't compile. With the library header names being too long, the
library might fail to compile or parts of it might be unusable.

> 
> If this is the case I may opt to merge the headers. i.e. _rw_has.h

I'd get rid of the _rw prefix and abbreviate the names. E.g., use
"ctor" instead of "constructor" etc. In fact, I wouldn't be at all
upset if we abbreviated the names of some the private traits as
well, e.g., truncate __rw_add_lvalue_reference to __rw_add_lval_ref
or something similar). Not just to spare us the typing a few extra
characters but also to reduce the sizes of symbol tables generated
for specializations involving these critters (FYI: this was bad
enough in C++ 98 that the IA64 ABI put in special cases for the
most egregious symbols: std::string and std::wstring).

On a related note, I wonder if it would make sense to consolidate
some of the implementation headers that we don't expect to be useful
in the rest of the library on their own (e.g., all the ctor
headers/traits).

> 
> 
>>  *  Do the trait member (e.g., _C_type, _C_value) need to be
>>     privatized or would it make more sense to use the required names?
> 
> I'm not sure what you're saying here. The types in the public interface
> all have the required names [from the base integral_constant template].
> 
> Everything else is an internal class, and I thought that we always
> needed to use privatized names for internal classes exposed in the
> headers. Using names consistent with those in the public interface
> doesn't buy us anything significant that I can think of, and there is no
> requirement that I know of saying we should.
> 
> Other than avoiding the additional three characters, Is there any
> motivation to switch? The _C_ thing is starting to grow on me.

Heh -- didn't I tell you it would? ;-)

The motivation for privatizing the names of implementation-defined
class members is to avoid clashing with user-defined macro names.
Since the names "type," "value," and "value_type" are used
throughout the library we don't need to privatize them (although
we certainly can for consistency).

One reason why I asked the question was that if we derived the
standard traits from the implementation-defined ones we wouldn't
need to re-declare these members. (I now see that we don't use
derivation).

Another, and probably far more important reason for keeping the
names of the members the same, to make our implementation traits
look and feel like standard traits, i.e., conform to the traits
requirements. Otherwise the rest of our library won't be able
to easily use the private traits.

> 
>> Regarding the supporting infrastructure (config tests and headers):
>>
>>  *  In etc/config/src/RVALUE_REFERENCE.cpp needs, the _TYPENAME
>>     macro isn't defined at this stage. Also, I'm not sure why
>>     the test needs to use templates at all.
> 
> You are right about the typename macro. I was being lazy and just copied
> a snippet of code out of the rvalue-reference proposal.
> 
>>  *  In etc/config/src/VARIADIC_TEMPLATES.cpp, shouldn't struct
>>     pack (the primary template) be defined?
> 
> No. I'm still a little new to this, but what you are calling the primary
> template is just a fwd declaration.
> 
> If you supply one or more template arguments, the first specialization
> will be used, otherwise the empty specialization will be used.
> 
>>     Also, is the empty specialization of pack valid?
> 
> I'm pretty sure it is. 14.3 p4 says
> 
>   When template argument packs or default template-
>   arguments are used, a template argument list can
>   be empty. In that case the empty <> brackets shall
>   still be used as the template argument list.

I see. I told you my C++ was getting rusty! But I'm becoming quite
good at awk! ;-)

> 
> The code is taken from Doug Gregor's Variadic Templates paper
> [http://tinyurl.com/48s8dr]. This paper is referenced from Proposed
> Wording for Variadic Templates [http://tinyurl.com/47n9uf] which appears
> to be the basis for the the wording in the current draft and the gcc-4
> implementation.
> 
> Perhaps I should write a simpler test.
> 
>>     Finally, even though it may
>>     not matter for correctness, the pack specialization should
>>     probably be defined as a struct rather than class.
> 
> Agreed.
> 
>>  *  In include/rw/_config-msvc.h: Would we have a naming conflict
>>     with any of our other macros if we dropped the _TT_ bit from
>>     the type traits macros? (I would prefer to keep the names of
>>     the macros short and as close to the type traits intrinsics
>>     as possible).
> 
> Well, I was supplying macros for the internal type trait names, but they
> don't really do anything other than cut down on the number of characters
> to type. If I eliminated, or renamed those, then I would be able to use
> the more appropriate names.
> 
>>  *  In include/rw/_defs.h, what is __NATIVE_TYPE_TRAITS_SUPPORTED
>>     and where does it come from?
> 
> It is from Howard Hinnant's original draft proposal for compiler support
> for type traits [http://tinyurl.com/3ez8ol]. I recently found James
> Widman's Compiler Support for type_traits proposal
> [http://tinyurl.com/3tyytp] and it removes the requirement for this
> macro.
> 
>>     I'm also concerned that the macro
>>     might be #defined but not all the traits might be supported or
>>     one of them might be spelled differently.
> 
> Yeah, the original proposal said that the macro would be defined if the
> compiler provided 'this interface', so I think it would need to provide
> exactly those names. Since the macro was removed from the current
> document I don't believe that I can rely on it, so I'll be removing the
> block from rw/_defs.h and add platform specific blocks somewhere else
> [probably in the _config-<compiler>.h files for now].
> 
>> I also noticed that some files (e.g., _is_floating_point.h) make
>> use of the _RWSTD_SPECIALIZED_CLASS macro while others assume
>> explicit specialization is supported. I suspect we might as well
>> assume it is and do away with the macro. Ditto for _TYPENAME.
>>
> 
> I tried to use the macros everywhere. Since we haven't finished up the
> discussion about what compiler features we can expect, I figured I had
> better stick with what we're already doing.

That sounds reasonable. We should just remember to do the cleanup
at some point before 4.3 goes out.

> 
>> Martin
>>
> 
> I'll try to post the updated patch this afternoon. That might get pushed
> back to tomorrow if the merge from 4.3 to trunk takes any more than a
> few hours.
> 
> Travis

Sounds good!
Martin

RE: type_traits progress

Posted by Travis Vitek <Tr...@roguewave.com>.
 

>Martin Sebor wrote:
>
>I haven't gone through the whole patch yet so just a few brief
>comments. I'll follow up with more once I've finished reviewing
>the rest.

Thanks. I already have a bunch of changes for gcc 4.3, so it might be
better to hold off. As you might expect MSVC allows some stuff that GCC
doesn't.

>First, some of your files are missing the final newline (required
>of text files by POSIX).
>
>Regarding style: The convention is
>
>     template <class>
>     struct S;
>
>rather than
>
>     template <class> struct S;
>

Will be fixed for next review.

>Regarding Copyrights: the year should be 2008 in all newly written
>code, and there's a missing ", Inc." at the end.
>

Darn. I thought I had copied the block from an up-to-date file. I'll fix
this also.

>Regarding naming:
>
>  *  File names should be abbreviated so as not to exceed the 14
>     character minimum required by POSIX.

I wasn't aware of a 14 character limit, and I'm guessing that this is to
do with the length of the header name as we don't limit the length of
the test names or config test names in any way.

If this is the case I may opt to merge the headers. i.e. _rw_has.h


>  *  Do the trait member (e.g., _C_type, _C_value) need to be
>     privatized or would it make more sense to use the required names?

I'm not sure what you're saying here. The types in the public interface
all have the required names [from the base integral_constant template].

Everything else is an internal class, and I thought that we always
needed to use privatized names for internal classes exposed in the
headers. Using names consistent with those in the public interface
doesn't buy us anything significant that I can think of, and there is no
requirement that I know of saying we should.

Other than avoiding the additional three characters, Is there any
motivation to switch? The _C_ thing is starting to grow on me.

>
>Regarding the supporting infrastructure (config tests and headers):
>
>  *  In etc/config/src/RVALUE_REFERENCE.cpp needs, the _TYPENAME
>     macro isn't defined at this stage. Also, I'm not sure why
>     the test needs to use templates at all.

You are right about the typename macro. I was being lazy and just copied
a snippet of code out of the rvalue-reference proposal.

>  *  In etc/config/src/VARIADIC_TEMPLATES.cpp, shouldn't struct
>     pack (the primary template) be defined?

No. I'm still a little new to this, but what you are calling the primary
template is just a fwd declaration.

If you supply one or more template arguments, the first specialization
will be used, otherwise the empty specialization will be used.

>     Also, is the empty specialization of pack valid?

I'm pretty sure it is. 14.3 p4 says

  When template argument packs or default template-
  arguments are used, a template argument list can
  be empty. In that case the empty <> brackets shall
  still be used as the template argument list.

The code is taken from Doug Gregor's Variadic Templates paper
[http://tinyurl.com/48s8dr]. This paper is referenced from Proposed
Wording for Variadic Templates [http://tinyurl.com/47n9uf] which appears
to be the basis for the the wording in the current draft and the gcc-4
implementation.

Perhaps I should write a simpler test.

>     Finally, even though it may
>     not matter for correctness, the pack specialization should
>     probably be defined as a struct rather than class.

Agreed.

>  *  In include/rw/_config-msvc.h: Would we have a naming conflict
>     with any of our other macros if we dropped the _TT_ bit from
>     the type traits macros? (I would prefer to keep the names of
>     the macros short and as close to the type traits intrinsics
>     as possible).

Well, I was supplying macros for the internal type trait names, but they
don't really do anything other than cut down on the number of characters
to type. If I eliminated, or renamed those, then I would be able to use
the more appropriate names.

>  *  In include/rw/_defs.h, what is __NATIVE_TYPE_TRAITS_SUPPORTED
>     and where does it come from?

It is from Howard Hinnant's original draft proposal for compiler support
for type traits [http://tinyurl.com/3ez8ol]. I recently found James
Widman's Compiler Support for type_traits proposal
[http://tinyurl.com/3tyytp] and it removes the requirement for this
macro.

>     I'm also concerned that the macro
>     might be #defined but not all the traits might be supported or
>     one of them might be spelled differently.

Yeah, the original proposal said that the macro would be defined if the
compiler provided 'this interface', so I think it would need to provide
exactly those names. Since the macro was removed from the current
document I don't believe that I can rely on it, so I'll be removing the
block from rw/_defs.h and add platform specific blocks somewhere else
[probably in the _config-<compiler>.h files for now].

>
>I also noticed that some files (e.g., _is_floating_point.h) make
>use of the _RWSTD_SPECIALIZED_CLASS macro while others assume
>explicit specialization is supported. I suspect we might as well
>assume it is and do away with the macro. Ditto for _TYPENAME.
>

I tried to use the macros everywhere. Since we haven't finished up the
discussion about what compiler features we can expect, I figured I had
better stick with what we're already doing.

>Martin
>

I'll try to post the updated patch this afternoon. That might get pushed
back to tomorrow if the merge from 4.3 to trunk takes any more than a
few hours.

Travis

Re: type_traits progress

Posted by Martin Sebor <se...@roguewave.com>.
I haven't gone through the whole patch yet so just a few brief
comments. I'll follow up with more once I've finished reviewing
the rest.

First, some of your files are missing the final newline (required
of text files by POSIX).

Regarding style: The convention is

     template <class>
     struct S;

rather than

     template <class> struct S;

Regarding Copyrights: the year should be 2008 in all newly written
code, and there's a missing ", Inc." at the end.

Regarding naming:

  *  File names should be abbreviated so as not to exceed the 14
     character minimum required by POSIX.
  *  Do the trait member (e.g., _C_type, _C_value) need to be
     privatized or would it make more sense to use the required names?

Regarding the supporting infrastructure (config tests and headers):

  *  In etc/config/src/RVALUE_REFERENCE.cpp needs, the _TYPENAME
     macro isn't defined at this stage. Also, I'm not sure why
     the test needs to use templates at all.
  *  In etc/config/src/VARIADIC_TEMPLATES.cpp, shouldn't struct
     pack (the primary template) be defined? Also, is the empty
     specialization of pack valid? Finally, even though it may
     not matter for correctness, the pack specialization should
     probably be defined as a struct rather than class.
  *  In include/rw/_config-msvc.h: Would we have a naming conflict
     with any of our other macros if we dropped the _TT_ bit from
     the type traits macros? (I would prefer to keep the names of
     the macros short and as close to the type traits intrinsics
     as possible).
  *  In include/rw/_defs.h, what is __NATIVE_TYPE_TRAITS_SUPPORTED
     and where does it come from? I'm also concerned that the macro
     might be #defined but not all the traits might be supported or
     one of them might be spelled differently.

I also noticed that some files (e.g., _is_floating_point.h) make
use of the _RWSTD_SPECIALIZED_CLASS macro while others assume
explicit specialization is supported. I suspect we might as well
assume it is and do away with the macro. Ditto for _TYPENAME.

Martin

Travis Vitek wrote:
> I've posted what I've got for the current type_traits implementation to
> STDCXX-916. I would have just mailed the file to the list directly, but
> it is pretty big.
> 
>     http://issues.apache.org/jira/browse/STDCXX-916
> 
> The tests do compile and run on VC8. There are still a few failures. I'm
> in the process of porting this to linux/gcc4.3 and I'm expecting the
> results to be a bit better there because all of the necessary compiler
> support is available.
> 
> Please review the code and provide feedback. It would be most helpful if
> any comments are pasted along with the block of code in question.
> 
> Also, please don't focus on formatting to much. I know that I have a few
> lines that run over 76 characters wide and that I've left out some
> spaces after commas and before open parens. I'll deal with that stuff on
> my own.
> 
> Note that some of the tests have type names that end in underscores.
> I'll be changing these to end in _t. It makes things more readable.
> 
> Travis


Re: type_traits progress

Posted by Martin Sebor <se...@roguewave.com>.
Travis Vitek wrote:
>  
> 
> Martin Sebor wrote:
>> One comment on the design of the tests: template instantiation
>> is very expensive both in terms of compiler cycles and in terms
>> of disk space taken up by the generated object code. We need to
>> avoid instantiating more than the bare minimum of code. So for
>> example, in tests/utilities/20.meta.help.cpp,
>> test_integral_constant() would ideally be an ordinary function
>> with the expected and tested values being passed in by the macro.
>> Also, if there's a way to avoid using function templates (such
>> as test_is_same_type) and use class templates instead it should
>> save us some cycles (especially with optimization) and disk
>> space.
> 
> This is an excellent point, and a relatively easy fix to apply in most
> cases.
> 
> A quick question on this subject. In many cases it is convenient to use
> traits in testing other traits. As an example I would like to use
> std::is_same<T,U>::value when testing traits like std::is_const. If I
> test is_same using hard coded values, is it acceptable to use is_same
> when testing other traits like add_const? If I don't use std::is_same,
> then I would need to write something similar to is_same [either a class
> or function template] to give me the answer. What does everyone think?

I normally try to avoid relying on parts of a tested product
to exercise others, but in this case it does seem like you
could end up duplicating much of the tested functionality
in the tests themselves. It's a judgment call.

Martin

> 
>> As an aside, tests don't need to use the _STD macro. The test
>> config header testdefs.h does the necessary magic to let us use
>> the name std directly even when _RWSTD_NO_NAMESPACE is #defined.
> 
> Hah, necessary magic equals #define. Yeah, I noticed this. I'll update
> my tests.
> 
>> Martin
>>


RE: type_traits progress

Posted by Travis Vitek <Tr...@roguewave.com>.
 

Martin Sebor wrote:
>
>One comment on the design of the tests: template instantiation
>is very expensive both in terms of compiler cycles and in terms
>of disk space taken up by the generated object code. We need to
>avoid instantiating more than the bare minimum of code. So for
>example, in tests/utilities/20.meta.help.cpp,
>test_integral_constant() would ideally be an ordinary function
>with the expected and tested values being passed in by the macro.
>Also, if there's a way to avoid using function templates (such
>as test_is_same_type) and use class templates instead it should
>save us some cycles (especially with optimization) and disk
>space.

This is an excellent point, and a relatively easy fix to apply in most
cases.

A quick question on this subject. In many cases it is convenient to use
traits in testing other traits. As an example I would like to use
std::is_same<T,U>::value when testing traits like std::is_const. If I
test is_same using hard coded values, is it acceptable to use is_same
when testing other traits like add_const? If I don't use std::is_same,
then I would need to write something similar to is_same [either a class
or function template] to give me the answer. What does everyone think?

>As an aside, tests don't need to use the _STD macro. The test
>config header testdefs.h does the necessary magic to let us use
>the name std directly even when _RWSTD_NO_NAMESPACE is #defined.

Hah, necessary magic equals #define. Yeah, I noticed this. I'll update
my tests.

>
>Martin
>

Re: type_traits progress

Posted by Martin Sebor <se...@roguewave.com>.
One comment on the design of the tests: template instantiation
is very expensive both in terms of compiler cycles and in terms
of disk space taken up by the generated object code. We need to
avoid instantiating more than the bare minimum of code. So for
example, in tests/utilities/20.meta.help.cpp,
test_integral_constant() would ideally be an ordinary function
with the expected and tested values being passed in by the macro.
Also, if there's a way to avoid using function templates (such
as test_is_same_type) and use class templates instead it should
save us some cycles (especially with optimization) and disk
space.

As an aside, tests don't need to use the _STD macro. The test
config header testdefs.h does the necessary magic to let us use
the name std directly even when _RWSTD_NO_NAMESPACE is #defined.

Martin

Travis Vitek wrote:
> I've posted what I've got for the current type_traits implementation to
> STDCXX-916. I would have just mailed the file to the list directly, but
> it is pretty big.
> 
>     http://issues.apache.org/jira/browse/STDCXX-916
> 
> The tests do compile and run on VC8. There are still a few failures. I'm
> in the process of porting this to linux/gcc4.3 and I'm expecting the
> results to be a bit better there because all of the necessary compiler
> support is available.
> 
> Please review the code and provide feedback. It would be most helpful if
> any comments are pasted along with the block of code in question.
> 
> Also, please don't focus on formatting to much. I know that I have a few
> lines that run over 76 characters wide and that I've left out some
> spaces after commas and before open parens. I'll deal with that stuff on
> my own.
> 
> Note that some of the tests have type names that end in underscores.
> I'll be changing these to end in _t. It makes things more readable.
> 
> Travis