1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
//Warning, C++11 code ahead
typedef std::set<std::string> _cendent_list;
// You can also extend this to include a list of non-family members
// if you want to catch those.
template <class Origin, class Relative>
void find_relationship_helper3(_cendent_list&, _cendent_list& des, std::true_type)
{
des.insert(typeid(Relative).name());
}
template <class Origin, class Relative>
void find_relationship_helper3(_cendent_list&, _cendent_list&, std::false_type)
{}
template <class Origin, class Relative>
void find_relationship_helper2(_cendent_list& ante, _cendent_list&, std::true_type)
{
ante.insert(typeid(Relative).name());
}
template <class Origin, class Relative>
void find_relationship_helper2(_cendent_list& ante, _cendent_list& des, std::false_type)
{
find_relationship_helper3<Origin, Relative>
(ante, des, typename std::is_base_of<Origin, Relative>::type());
}
template <class Origin, class Relative>
void find_relationship_helper(_cendent_list& ante, _cendent_list& des)
{
find_relationship_helper2<Origin, Relative>
(ante, des, typename std::is_base_of<Relative, Origin>::type());
}
template <class Origin, class Relative, class Relative2, class... FamilyPack>
void find_relationship_helper(_cendent_list& ante, _cendent_list& des)
{
find_relationship_helper<Origin, Relative>(ante, des);
find_relationship_helper<Origin, Relative2, FamilyPack...>(ante, des);
}
//Important function here
template <class Origin, class... FamilyPack>
std::pair<_cendent_list, _cendent_list> find_relationship()
{
_cendent_list ante, des;
find_relationship_helper<Origin, FamilyPack...>(ante, des);
return std::make_pair(ante, des);
}
|