Boost logo

Boost Users :

From: Chris Fairles (chris.fairles_at_[hidden])
Date: 2007-07-20 18:03:18


How can you determine (compile-time) that a class has a serialize function?

struct foo {
template <typename Archive>
void serialize (Archive &, const unsigned int);
};

"&foo::serialize" isn't a type and I can't figure out a way to make it
a type (besides a typedef in the class) and also a constant
expression.

Tried to play around with this as well but theres no substitution
failure here and static functions can't be constant expressions
(commonnnn c++0x!!)

struct serialize {
    template <typename T>
    static void value(T const&) { void(T::*f)(archive::xml_oarchive &,
const unsigned int) = &T::template serialize<archive::xml_oarchive>;
(void)f; }
};

Basically, in the code below I want to see "GoodGood" printed out and
the only thing I can change is Q.

struct A{
  void f(int,int){}
};
struct B{};

template <class T,class F=void>
struct Q{enum{value=false};};

template<class T> struct Q<T,void(T::serialize)(int,int)>{enum{value=true};};

int main(){
  if(Q<A>::value) { cout << "Good";}
  if(!Q<B>::value){ cout << "Good";}
}

Help/hints/remotely possible?

Thanks,
Chris

On 4/20/07, Robert Ramey <ramey_at_[hidden]> wrote:
> a type is serializable if its a primtive or it has a serialize function.
>
> Robert Ramey
>
>
> Sohail Somani wrote:
> > Hi,
> >
> > I know there is the tracking level trait. Is that sufficient to be
> > able to say that T is serializable?
> >
> > struct T
> > {
> > T(some_stuff);
> > private:
> > some_non_default_constructing_members;
> > };
> >
> > In this case, I think tracking level will be set to track selectively
> > but its not serializable as is.
> >
> > Thanks,
> >
> > Sohail
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


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