Boost logo

Boost Users :

From: khasimo (skhabbaz_at_[hidden])
Date: 2006-02-15 06:52:42


Hi there,

I'm trying to port the xmlbeansxx library
(sourceforge.net/projects/xmlbeansxx) under windows using "Borland C++
5.6.4". The thing is I am having trouble with the "enable_if"
construction. From the "config\compiler\borland.hpp", I know that the
bcc compiler do not support SFINAE trick and so the "enable_if" and like
   constructions. In order to continue the port I have to modify the
"enable_if" implementation with something equivalent. Here is the code :

template<typename TO, typename FROM, typename Enable = void>
class cast_traits {
     public:
     TO operator ()(const FROM &from) const {
         return (TO)(from);
     }
};

class Ptr {
     public:
     template <typename TYPE, typename TYPE_I>
     static inline TYPE ptrFromThis(const boost::shared_ptr<TYPE_I> &from) {
         TYPE n;
         n.ptr = from;
         return n;
     }
};

/* (2) begin */
template<typename TO, typename FROM>
class cast_traits<TO, FROM,
         typename boost::enable_if<
             boost::mpl::and_<
                 boost::is_base_and_derived<Ptr, FROM>,
                 boost::is_base_and_derived<Ptr, TO>
>
>::type
> {
     public:
     TO operator ()(const FROM &from) const {
         TO r;
         r.ptr = ptr_cast<typename TO::value_type>(from.ptr);
         return r;
     }
};
/* (2) end */

template<typename TO, typename FROM>
inline TO cast(const FROM &from) {
     return cast_traits<TO, FROM>()(from);
}

My problem is with the "/*(2)*/" part of the code.

In the library code there is other constructions based on "enable_if"
but they are the same as the "/*(2)*/" example.

Thanks folks in advance. I'am really a newbie to boost (and templates)
and have no idea about a workaround.

PS: It is obvious that I will contribute the port to the xmlbeansxx project.


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