标签:继承 span volatile dex decltype a.out vol ... 可变
https://www.zhihu.com/question/51253466
#include <iostream>
#include <fstream>
#include <memory>
#include <iterator>
#include <type_traits>
#include <cstdlib>
#include <memory>
#include <cxxabi.h>
#include <type_traits>
#include <typeinfo>
#ifndef _MSC_VER
# include <cxxabi.h>
#endif
#include <memory>
#include <string>
#include <cstdlib>
template <class T>
std::string type_name()
{
typedef typename std::remove_reference<T>::type TR;
std::unique_ptr<char, void(*)(void*)> own
(
#ifndef _MSC_VER
abi::__cxa_demangle(typeid(TR).name(), nullptr,
nullptr, nullptr),
#else
nullptr,
#endif
std::free
);
std::string r = own != nullptr ? own.get() : typeid(TR).name();
if (std::is_const<TR>::value)
r += " const";
if (std::is_volatile<TR>::value)
r += " volatile";
if (std::is_lvalue_reference<T>::value)
r += "&";
else if (std::is_rvalue_reference<T>::value)
r += "&&";
return r;
}
using namespace std;
std::string demangle(const char* name);
inline std::string demangle(const char* name)
{
int status = -4;
std::unique_ptr<char, void(*)(void*)> res
{
abi::__cxa_demangle(name, NULL, NULL, &status),
std::free
};
return (status==0) ? res.get() : name ;
}
template<int...>
struct IndexSeq {};
template<int N, int... Indexes>
struct MakeIndexes : MakeIndexes<N - 1, N - 1, Indexes...>
{
MakeIndexes()
{
Init(demangle(typeid(this).name()));
}
void Init(std::string id)
{
std::cout<<"Creating "<<id<<std::endl;
}
};
template<int... indexes>
struct MakeIndexes<0, indexes...>
{
typedef IndexSeq<indexes...> type;
MakeIndexes()
{
Init(demangle(typeid(this).name()));
}
void Init(std::string id)
{
std::cout<<"Creating "<<id<<std::endl;
}
};
int main()
{
MakeIndexes<3> a;
MakeIndexes<3>::type b;
std::cout<<"*************************************"<<std::endl;
std::cout<<type_name<decltype(a)>()<<std::endl;
std::cout<<type_name<decltype(b)>()<<std::endl;
}
[root@VM_99_227_centos dev]# ./a.out
Creating MakeIndexes<0, 0, 1, 2>*
Creating MakeIndexes<1, 1, 2>*
Creating MakeIndexes<2, 2>*
Creating MakeIndexes<3>*
*************************************
MakeIndexes<3>
IndexSeq<0, 1, 2>
继承关系:
MakeIndexes<3> : MakeIndexes<2, 2>
MakeIndexes<2, 2> : MakeIndexes<1,1,2>
MakeIndexes<1,1,2>: MakeIndexes<0, 0,1,2>
index 可变模板展开
标签:继承 span volatile dex decltype a.out vol ... 可变
原文地址:http://www.cnblogs.com/abelian/p/6291854.html