Work on a template specialization error in VC ++ 12?

I have code written for Clang 3.2 that I am trying to run to run in VC ++ 12. Clang 3.2+ and GCC 4.8 have no problem with this, but VC ++ 12 complains. Here is the minimal snippet that causes the problem:

template <int(*ptr)()>
class foo {};

template<int N>
int ReturnsN() { return N; }

template<int N>
class bar {
  typedef foo<ReturnsN<N>> fooN; 
};

Now I'm sure this is a compiler error (but please let me know if it is not!) An error has occurred:

'specialization' : cannot convert from 'int (__cdecl *)(void)' to 'int (__cdecl *)(void)'

So does anyone know a decent job? It seems that the compiler is convinced that the specialized function is not fully defined.

EDIT: I should also note that I tried this with both the compiler and CTP in November 2013. Both problems are the same.

+4
source share
3

, connect:

template < int (*)() >
class foo {};

template<int N>
int ReturnsN( ) { return N; }

template<int N>
class bar {
    static int myReturnsN() { return ReturnsN<N>; }
    using fooN = foo< myReturnsN >;
};
+3

, - , , . - , , :

template <int(*ptr)()>
class foo {};

template<int N>
int ReturnsN() { return N; }

template<int N>
class bar {
private:
  static int Hack() {
    return ReturnsN<N>();
  }
public:
  typedef foo<Hack> fooN;
};

VS2012, VS2013 VS2013 CTP.

+3

ReturnsN static member member :

template <int(*)()>
class foo;

template <int N>
struct Wrapper {
    static int ReturnsN() { return N; }
};

template <int N>
class bar {
    typedef foo<Wrapper<N>::ReturnsN> fooN; 
};

V++ 2013.

0

Source: https://habr.com/ru/post/1525871/


All Articles