Sign in to follow this  

Template Ambiguity

This topic is 412 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I currently have

  template<class T>
  bool vs(const SC::Aggregate& a, const T& b) {
    //WARNING: see bool vs(const SC::Aggregate& a, const SC::Aggregate& b)
    //if this fn is modified
    for(auto& p : a.points)  { if(vs(p, b)) { return true; } }
    for(auto& c : a.circles) { if(vs(c, b)) { return true; } }
    for(auto& r : a.rects)   { if(vs(r, b)) { return true; } }
    return false;
  }

  template<class T>
  bool vs(const T& a, const SC::Aggregate& b) {
    return vs(b, a);
  }

  bool vs(const SC::Aggregate& a, const SC::Aggregate& b) {
    //~~@ ideally this would invoke the first overload instead
    for(auto& p : a.points)  { if(vs(p, b)) { return true; } }
    for(auto& c : a.circles) { if(vs(c, b)) { return true; } }
    for(auto& r : a.rects)   { if(vs(r, b)) { return true; } }
    return false;
  }

I'm wondering if there's a way to express that Aggregate v Aggregate should be handled by the first one there, rather than having to clone the code like this.

Share this post


Link to post
Share on other sites

It's more a case of not wanting to write the same code in multiple places. It's adjacent to some DD though. One sec, I'll push it and post the github.

 

https://github.com/khatharr/SimpleCollision/blob/master/SimpleCollision/simpleCollision.cpp

https://github.com/khatharr/SimpleCollision/blob/master/SimpleCollision/simpleCollision.h

 

main.cpp is not presentable at the moment.

 

Edit: Actually, yeah, I guess this would count as DD as well, lol. In this specific case I just want to be able to call vs() without looking up argument order.

 

I should mention that I'm aware that this would be a lot better without the polymorphism that is at the root of this madness. I'm planning to factor that out later. At this point I'm specifically exploring this structure to see what kind of weirdness comes out of it. It was something that I had done a long time ago and now that I'm doing my own work again I wanted to look at it with new eyes.

Edited by Khatharr

Share this post


Link to post
Share on other sites

This topic is 412 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

Sign in to follow this