vendredi 31 juillet 2015

Compile time Restricted Templates without use of boost

this is related to these two questions:

  1. standard c++11 way to remove all pointers of a type
  2. Compile Time Template restriction C++

the second one is mine

the issue is when i moved to TDM-GCC 64 the following code (previously working crashes) I made sure c++11 is enabled.

template<typename _Ty,
typename enable_if< is_base_of<OverVoid, remove_all_pointers<_Ty>::type>::value>::type>
class Move{
public:
    Move()
    {
        cout<<"### "<<remove_all_pointers<_Ty>::type::isOverVoid()<<endl;
    }
};


int main(){

    Move<Meta***> z;
    Move<Meta**> w;
    Move<Meta*> x;
    Move<Meta> y;

}

it displays the following error

Info: Internal Builder is used for build
g++ -std=c++0x -std=c++11 -std=gnu++11 -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\helllo_world.o" "..\\src\\helllo_world.cpp" 
In file included from ..\src\helllo_world.cpp:1:0:
..\src\Move.h:54:111: error: type/value mismatch at argument 2 in template parameter list for 'template<class, class> struct std::is_base_of'
 template<typename _Ty,class = typename std::enable_if<std::is_base_of<OverVoid, remove_all_pointers<_Ty>::type>::value>::type>
                                                                                                               ^
..\src\Move.h:54:111: note:   expected a type, got 'remove_all_pointers<T>::type'
..\src\Move.h:54:119: error: template argument 1 is invalid
 template<typename _Ty,class = typename std::enable_if<std::is_base_of<OverVoid, remove_all_pointers<_Ty>::type>::value>::type>
                                                                                                                       ^
..\src\helllo_world.cpp: In function 'int main()':
..\src\helllo_world.cpp:31:14: error: template argument 2 is invalid
  Move<Meta***> z;
              ^
..\src\helllo_world.cpp:32:13: error: template argument 2 is invalid
  Move<Meta**> w;
             ^
..\src\helllo_world.cpp:33:12: error: template argument 2 is invalid
  Move<Meta*> x;
            ^
..\src\helllo_world.cpp:34:11: error: template argument 2 is invalid
  Move<Meta> y;
           ^
..\src\helllo_world.cpp:31:16: warning: unused variable 'z' [-Wunused-variable]
  Move<Meta***> z;
                ^
..\src\helllo_world.cpp:32:15: warning: unused variable 'w' [-Wunused-variable]
  Move<Meta**> w;
               ^
..\src\helllo_world.cpp:33:14: warning: unused variable 'x' [-Wunused-variable]
  Move<Meta*> x;
              ^
..\src\helllo_world.cpp:34:13: warning: unused variable 'y' [-Wunused-variable]
  Move<Meta> y;
             ^

Aucun commentaire:

Enregistrer un commentaire