I want to make integral constant from char* and "kernel32.dll", but failed always. The following are my failed attempts, anyone can show me the correct usage?
error 1: cout << std::integral_constant<const char*, "kernel32.dll">::value << endl;
error 2: cout << std::integral_constant<char*, "kernel32.dll">::value << endl;
error 3: cout << std::integral_constant<char[], "kernel32.dll">::value << endl;
error 4: cout << cout << std::integral_constant<char*, static_cast<char*>("kernel32.dll")>::value << endl;
the above 4 statements have the same error info.:
Console.cpp(181): error C2762: 'std::integral_constant' : invalid expression as a template argument for '_Val'
1> D:\Programfiles\Visual Studio 2013\VC\include\xtr1common(35) : see declaration of 'std::integral_constant'
1>Console.cpp(181): error C2955: 'std::integral_constant' : use of class template requires template argument list
1> D:\Programfiles\Visual Studio 2013\VC\include\xtr1common(35) : see declaration of 'std::integral_constant'
1>Console.cpp(181): warning C4552: '<<' : operator has no effect; expected operator with side-effect
Update:
std::integral_constant<std::string, "abc">::value
won't compile either.
end update
Here is my scenario, I make a simple demo to demonstrate my purpose:
#include <iostream>
#include <type_traits>
template< typename R, typename C, typename... Args>
class delegate
{
public:
template<R(C::*F)(Args...), typename ... Ts>
struct adapter
{
static R invoke_no_fwd(Args... args)
{
C t((Ts::value)...);
return (t.*F)(args...);
}
};
};
class Class
{
public:
Class(const char* psz) {
std::cout << psz << std::endl;
}
void print(int v)
{
std::cout << "Class: " << v << std::endl;
}
};
int main()
{
typedef void(*function_t)(int);
function_t ptrFunc = delegate<void, Class, int>::adapter<&Class::print, std::integral_constant<char*, "money"> >::invoke_no_fwd;
auto type = delegate<void, Class, int>::adapter<&Class::print, std::integral_constant<int, 42>>::invoke_no_fwd;
ptrFunc(-42); // 0
type(0); // 42
return 0;
}