Sign in to follow this  
  • entries
    88
  • comments
    117
  • views
    61969

Wrestling with C++ templates

Sign in to follow this  
dcosborn

172 views

Today I was working on a way to pass generic containers to my serialization functions. I used SFINAE with enable_if to separate the container functions from the others. For this to work, I wrote a bunch of traits for containers, such as has_push_back and has_insert. The container deserialization functions used these to specialize for containers that were capable of working with std::back_inserter and std::inserter. Additionally, I used has_begin_end to detect serializable containers. As far as the standard containers were concerned, this worked fine. Not so with some of my math primitives, which use inheritance. AFAIK, this code has no solution for D:

struct B
{
void begin();
void begin() const;
};
struct D : B {};

template void (T:: *)() = &T::begin> struct with_begin;

typedef with_begin BT; // works
typedef with_begin DT; // fails

So I've dropped container serialization for the moment; iterator serialization does the job anyway. Meanwhile I'm waiting desperately for C++0x...

"...to make it compile will be such a trial as to kindle its self-immolation" (ISO/IEC 14882:2003 14.7.3.8).
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now