[C++-sig] pickle support patches checked in

David Abrahams david.abrahams at rcn.com
Mon Jul 22 14:25:25 CEST 2002


From: "Ralf W. Grosse-Kunstleve" <rwgk at yahoo.com>


> I have just checked in the patches that complete the pickle support.
> This is tested with VC6, CodeWarrior 7.2, cxx 6.5 and gcc 3.0.4.
> If the 8-platform auto-build in a few minutes shows any problems I will
> address them tomorrow morning.
>
> Regarding documentation: there is one additional class_<> member
> function: def_pickle(). I am uncertain how to document pickle_group.
> The public static functions are of no value to the user. They are just
> there to enable the compile-time error messages(**). Would it be best
> to just document a "pickle_group concept?"

Probably not, because everyone will want to use your base class; there's no
disadvantage.
However, it would be nice if you'd enforce that they used your base class
by attempting to convert to a pickle_fucntions*.

> (**) It would help in my case if C++ had smarter rules for resolving:
>
> struct base { static void foo(); }
> struct user { static void foo(); }
> struct merge : user, base
> {
> };
>
> merge::foo(); // according to the current standard "ambiguous"
>
> I also tried:
>
> struct base { static void foo(); }
> struct user { static void foo(); }
> struct intermediate : base {}; // to create "a larger distance"
> struct merge : user, intermediate
> {
> };
>
> merge::foo(); // still "ambiguous"
>
> Isn't that a real obstacle to meta-programming?

Not really. You just want to detect the presence of a member, and
conforming compilers will already do that. However, most of your compilers
don't conform.


template <int> struct sz {};

// overload resolution fails if no some_member member
template <class T>
char has_some_member_helper(sz<sizeof(T::some_member)>*);

// This one gets selected instead
template <class T> char(& has_some_member_helper(...) )[4];

// Here's the user-friendly template
template <class T>
struct has_some_member
{
    static bool const value = (
        sizeof(has_some_member_helper<T>(0)) == sizeof(char));
};

-Davew






More information about the Cplusplus-sig mailing list