[ create a new paste ] login | about

Link: http://codepad.org/k4dOuaZy    [ raw code | output | fork ]

C++, pasted on Feb 13:
#include <boost/mpl/apply.hpp>

template<class T, class R=void>  struct enable_if_type { typedef R type; };

template<template<class,class> class T, class A, class B, class Enable=void>
struct select_proper_specialization
{
  template<class X,class Y> struct apply
  {
    typedef T<Y,X> type;
  };
};

template<template<class,class> class T, class A, class B>
struct select_proper_specialization<T,A,B, typename enable_if_type< T<A,B> >::type>
{
  template<class X,class Y> struct apply
  {
    typedef T<X,Y> type;
  };
};

template<class A,class B> struct foo;
template<> struct foo<int,float> 
{ 
  static void Test() { cout << "foo<A,B>" << endl; }
};

int main()
{
  boost::mpl::apply< select_proper_specialization<foo,int,float>,int,float>::type::Test();
  boost::mpl::apply< select_proper_specialization<foo,float,int>,float,int>::type::Test();
}


Output:
1
2
3
In function 'int main()':
Line 32: error: incomplete type 'foo<float, int>' used in nested name specifier
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: