Boost logo

Boost Users :

From: Kevin Jenkins (gameprogrammer_at_[hidden])
Date: 2008-09-03 10:47:27


Hi,

I'm trying to use typedef typename boost::mpl::if_ to choose between
two structures, both with identical function names, so I can choose
which function to call based on the template parameter type.

The code works fine on Visual Studio 2005. But in MinGW/MSys it returns:

RPC3_Boost.h:203: error: template argument 2 is invalid
RPC3_Boost.h:203: error: template argument 3 is invalid
RPC3_Boost.h:203: error: ISO C++ forbids declaration of `type' with no
type

This is with boost_1_35_0. I've cut out as much code as I can:

struct ReadBitstream {
        static void apply(RakNet::BitStream &bitStream, RakNet::BitStream* t)
{/* ... */}
};

template <typename T>
struct ReadPtr {
        static inline void apply(RakNet::BitStream &bitStream, const char
*&t) {applyStr(bitStream, (char *&) t);}
};

template< typename T >
struct DoRead {
        typedef typename boost::mpl::if_<
                boost::is_convertible<T*,RakNet::BitStream*>,
                typename ReadBitstream,
                typename ReadPtr<T> >::type type;
};

To call the function, I use:

DoRead< boost::remove_pointer<T>::type >::type::apply(*
(args.bitStream),&t);

Thanks in advance for any help.

The whole file is here if you need to see more code:
https://raknetjenkinsso.svn.sourceforge.net/svnroot/raknetjenkinsso/trunk/DependentExtensions/RPC3/RPC3_Boost.h


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net