Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Wrestling with C++ templates

Sign in to follow this  


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
Sign in to follow this  


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
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!