#include
using namespace std;
class Fun
{
struct InnerType
{
int i{42};
};
public:
auto run()
{
return InnerType{};
}
auto run2() -> InnerType;
};
template< typename R, typename _>
void extractInnerType( R(_::*)() )
{
cout << R{}.i << endl;
}
template< typename T>
T innerType{};
int main(void)
{
// Blog's question:
Fun f;
decltype(f.run()) d{};
cout << d.i << endl;
//variable template
cout << innerType<decltype(f.run())>.i << endl;
//--- c++98 style
extractInnerType(true ? nullptr : &Fun::run2);
}
Jun 11, 2015
[c++] extract inner type
Labels:
cpp,
cpp_note,
cpp_original,
cpp_sample,
cpp11,
cpp14
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.