stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Travis Vitek" <>
Subject RE: implementation of Unary Traits
Date Fri, 27 Jun 2008 00:54:45 GMT

Martin Sebor wrote:
>The implementation of Unary Traits (e.g., is_void) uses explicit
>specialization on all four combinations of cv-qualifiers for each
>trait (plain, const, volatile, and const volatile). I'm wondering
>if the alternative approach of stripping the qualifiers before
>"dispatching" to just one explicit specialization has been

That is what I had originally done. The following code may be eerily
familiar to you.

  #include <tr1/_remove_cv.h>
  #include <rw/_defs.h>


  template <class _TypeT> struct __rw_is_void_impl
      enum { _C_value = 0 };

  _RWSTD_SPECIALIZED_CLASS struct __rw_is_void_impl<void>
      enum { _C_value = 1 };
  template <class _TypeT> struct __rw_is_void
      enum { _C_value = 
              _TYPENAME __rw_remove_cv<_TypeT>::_C_type

  } // namespace __rw

The only issue is that this creates a cyclic dependency between traits
defined in <rw/_meta_cv.h> and those in <rw/_meta_cat.h>. An easy way to
'fix' this would be to forward declare __rw_remove_cv in
<rw/_meta_cat.h> and then include <rw/_meta_cv.h> at the bottom, but
this goes against our conventions. Another option was to put the
remove-cv traits into their own header, but this went against your
request to organize the traits in files according to some rationale.

>The potential advantage of this approach is fewer
>declarations, smaller translation units, and thus (presumably)
>faster compilation.

There has to be a balance somewhere. If all traits are in one file, we
have few includes, but lots of unnecessary declarations. If we spread
them all out, then we have few unnecessary declarations, but many
includes. Both can _potentially_ lead to (ever so slightly) longer
compile times in some cases and shorter ones in other cases.

I'm definitely open to suggestions and I'm willing to make any necessary
changes. Unfortunately any suggestion has to take the following criteria
into consideration...

  A. the number of trait headers should be kept to a minimum (to keep
compile times down)
  B. there should not be many unnecessary declarations in any header (to
keep compile times down)
  C. traits should be put into files according to some well defined
rationale (to keep things organized)

Unfortunately, I don't really see a clear path to satisfying all of the
above requirements.


View raw message