Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 18, 2010, 3:39:01 PM (14 years ago)
Author:
landauf
Message:

merged consolecommands2 to consolecommands3

Location:
code/branches/consolecommands3
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • code/branches/consolecommands3

  • code/branches/consolecommands3/src/libraries/util/Convert.h

    r7163 r7179  
    116116        }
    117117    };
     118
     119    ////////////
     120    // upcast //
     121    ////////////
     122    namespace detail
     123    {
     124        // perform a static cast if ToType is a base of FromType
     125        template<class ToType, class FromType>
     126        FORCEINLINE ToType upcast(FromType input, detail::Int2Type<true>)
     127        {
     128            return static_cast<ToType>(input);
     129        }
     130
     131        // return zero if ToType is not a base of FromType
     132        template<class ToType, class FromType>
     133        FORCEINLINE ToType upcast(FromType input, detail::Int2Type<false>)
     134        {
     135            return 0;
     136        }
     137    }
     138
     139    // performs an upcast if ToType is a base of FromType, returns zero otherwise
     140    template <class ToType, class FromType>
     141    FORCEINLINE ToType upcast(FromType input)
     142    {
     143        enum { probe = ImplicitConversion<FromType, ToType>::exists };
     144        return detail::upcast<ToType, FromType>(input, detail::Int2Type<probe>());
     145    }
    118146}
    119147
Note: See TracChangeset for help on using the changeset viewer.