Template to remove reference.

Discussion in 'C++' started by jeff_d_harper@hotmail.com, Oct 28, 2005.

  1. Guest

    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.
     
    , Oct 28, 2005
    #1
    1. Advertising

  2. mlimber Guest

    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
     
    mlimber, Oct 28, 2005
    #2
    1. Advertising

  3. mlimber wrote:
    > 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.
     
    Victor Bazarov, Oct 28, 2005
    #3
  4. Guest

    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_typetraits/category.html#transform.broken_compiler_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.
     
    , Oct 28, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simon-Pierre  Jarry
    Replies:
    2
    Views:
    2,377
    Henrik
    Aug 10, 2005
  2. Chris Theis
    Replies:
    2
    Views:
    478
    Chris Theis
    Jul 24, 2003
  3. tom_usenet
    Replies:
    0
    Views:
    538
    tom_usenet
    Jul 24, 2003
  4. tshad
    Replies:
    6
    Views:
    21,469
    tshad
    Aug 8, 2006
  5. mrstephengross
    Replies:
    2
    Views:
    407
    mrstephengross
    Sep 7, 2005
Loading...

Share This Page