Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Template to remove reference.

Reply
Thread Tools

Template to remove reference.

 
 
jeff_d_harper@hotmail.com
Guest
Posts: n/a
 
      10-28-2005
Hi,

I need a template that will remove references from a type. Suppose the
template I need is named Drop_ref. I'd like to do something like this
.. . .

Drop_ref<SomeClass &>::type InstanceOfSomeClass;

would be equivalent to

SomeClass InstanceOfSomeClass;


Unfortunately, it must work with a C++ compiler that does not have
partial template specialization. Microsoft has yet to bring Embedded
Visual C++ up to ISO standards. If someone could post a work around
I'd be very appreciative.

 
Reply With Quote
 
 
 
 
mlimber
Guest
Posts: n/a
 
      10-28-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi,
>
> I need a template that will remove references from a type. Suppose the
> template I need is named Drop_ref. I'd like to do something like this
> . . .
>
> Drop_ref<SomeClass &>::type InstanceOfSomeClass;
>
> would be equivalent to
>
> SomeClass InstanceOfSomeClass;
>
>
> Unfortunately, it must work with a C++ compiler that does not have
> partial template specialization. Microsoft has yet to bring Embedded
> Visual C++ up to ISO standards. If someone could post a work around
> I'd be very appreciative.


See the implementations in Boost.TypeTraits (http://boost.org) and Loki
(http://sourceforge.net/projects/loki-lib/). They both have some tricks
to make it work with VC++ 6.

Cheers! --M

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      10-28-2005
mlimber wrote:
> (E-Mail Removed) wrote:
>>[...request that could be easily satisfied with partial specialisation...]
>>Unfortunately, it must work with a C++ compiler that does not have
>>partial template specialization. Microsoft has yet to bring Embedded
>>Visual C++ up to ISO standards. If someone could post a work around
>>I'd be very appreciative.

>
>
> See the implementations in Boost.TypeTraits (http://boost.org) and Loki
> (http://sourceforge.net/projects/loki-lib/). They both have some tricks
> to make it work with VC++ 6.


VC++ 6 is actually more advanced than Embedded VC++, or so I heard.
 
Reply With Quote
 
jeff_d_harper@hotmail.com
Guest
Posts: n/a
 
      10-28-2005
I'd already checked out Boost. Unfortunately, it looks like it is not
possible to remove a reference with boost unless the compiler supports
partial template specialization. Or, a macro is used to setup type
traits for user defined types.

http://www.boost.org/doc/html/boost_...r_workarounds_

At your suggestion I looked at Loki. Unfortunately, it doesn't look
like the TypeTraits<T>::ReferredType is implemented in the VC6 version
of Loki.

In fact, when I grepped the VC6 Loki header files for ReferredType, I
found this comment:

//TODOSGB None of the parameter types are defined inside of TypeTraits,
e.g. PointeeType, ReferredType, etc...

I will probably implement a solution similar to Boost's "broken
compiler work around" where I use a macro to setup a type trait for all
my UDTs.

I look forward to the day when I no longer have to worry about how
complete my compiler's template support is.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
r H2 deduce deduce template argument of a template class inheritingfrom a non template base? nguillot C++ 5 03-08-2009 05:56 PM
How to use the template member function of a template in the memberfunction of another template class? Peng Yu C++ 3 10-26-2008 03:51 PM
template template arguments: expected a class template, got `Component<T1, T2, T3> gary.bernstein@gmail.com C++ 1 06-08-2007 07:10 AM
Re: A Newbie Question about template template template tom_usenet C++ 0 07-24-2003 12:06 PM
Re: A Newbie Question about template template template Chris Theis C++ 2 07-24-2003 09:42 AM



Advertisments