Jump to content
  • Advertisement
Sign in to follow this  
Shnoutz

C++ Template specialization selection/ambiguity

This topic is 422 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

Hi, quick question.. Why is the type of "fooBar" ambiguous?

template< typename T >
struct Bar
{
};

template< typename T1, typename T2 >
struct Foo;

template< typename T >
struct Foo< T, Bar< T > >
{
};

template< typename T >
struct Foo< float, Bar< T > >
{
};

Foo< float, Bar< float > > fooBar;

I would expect that the second version of Foo is more specialized than the first...

(I am building a compiler and I would like to understand the template specialization selection algorithm)

Cheers!

Share this post


Link to post
Share on other sites
Advertisement

For a quick reference, you can look at the summary of the specialization rules here:

http://en.cppreference.com/w/cpp/language/partial_specialization

Under "Partial Ordering", you'll find an explanation of how the process of specialization selection works. If I understand it correctly, with the proposed specialization selection algorithm, both of your templates could potentially be a subset of each other and thats why it fails - though I'm not 100% sure, but you can just try it out and see for yourself :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

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