Quantcast
Channel: Intel® Software - Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1175

Issue with static_cast and decltype

$
0
0

The following code fails to compile with Intel C++ 17.0 but compiles fine with MSVC & gcc. If I use a typedef instead of decltype, then it compiles OK.

#include <iostream>

template<class Sig, Sig Func> struct MyFunc;
template<class T, class... Args, void (T::*Func)(Args...) const>
struct MyFunc<void (T::*)(Args...) const, Func>
{
  static void execute(const T *obj)
  {
    (obj->*Func)();
  }
};
template<class T, class... Args, void (T::*Func)(Args...)>
struct MyFunc<void (T::*)(Args...), Func>
{
  static void execute(T *obj)
  {
    (obj->*Func)();
  }
};

#define MYFUNC(...) MyFunc<decltype(__VA_ARGS__), __VA_ARGS__>

struct A
{
  void func() const { std::cout << "in A::func() const"<< std::endl; }
  void func() { std::cout << "in A::func()"<< std::endl; }
};

int main()
{
  A a;
  MYFUNC(static_cast<void(A::*)() const>(&A::func))::execute(&a);
  MYFUNC(static_cast<void(A::*)()>(&A::func))::execute(&a);
};

Viewing all articles
Browse latest Browse all 1175

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>