Skip to content

Instantly share code, notes, and snippets.

@griwes
Last active August 10, 2017 11:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save griwes/e7a467d24e9f016c0d68 to your computer and use it in GitHub Desktop.
Save griwes/e7a467d24e9f016c0d68 to your computer and use it in GitHub Desktop.
template<typename Type, typename Tag = class default_tag>
struct list_mixin
{
Type * prev = nullptr;
Type * next = nullptr;
};
template<typename CRTP, typename... Tags>
struct list_mixins : list_mixin<CRTP, Tags>...
{
template<typename T>
auto & prev()
{
return static_cast<list_mixin<CRTP, T> &>(*this).prev;
}
template<typename T>
auto & prev() const
{
return static_cast<const list_mixin<CRTP, T> &>(*this).prev;
}
template<typename T>
auto & next()
{
return static_cast<list_mixin<CRTP, T> &>(*this).next;
}
template<typename T>
auto & next() const
{
return static_cast<const list_mixin<CRTP, T> &>(*this).next;
}
};
class thread : public list_mixins<thread, class all, class same_state>
{
};
#include <iostream>
int main()
{
std::cout << thread{}.prev<class all>();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment