meta_list.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "simple/support/meta/list.hpp"
  2. #include <type_traits>
  3. using namespace simple::support;
  4. template <typename...> struct some_other_list {};
  5. int main()
  6. {
  7. using a = meta::list<long, int, short, char>;
  8. static_assert(meta::list_size_v<a> == 4);
  9. static_assert(std::is_same_v<meta::list_element_t<0, a>, long>);
  10. static_assert(std::is_same_v<meta::list_element_t<1, a>, int>);
  11. static_assert(std::is_same_v<meta::list_element_t<2, a>, short>);
  12. static_assert(std::is_same_v<meta::list_element_t<3, a>, char>);
  13. static_assert(std::is_same_v<meta::collect_list_t<a, std::index_sequence<1,2>>, meta::list<int, short>>);
  14. static_assert(std::is_same_v<meta::collect_list_t<a, std::index_sequence<1,3>>, meta::list<int, char>>);
  15. static_assert(std::is_same_v<meta::collect_list_t<a, std::index_sequence<>>, meta::list<>>);
  16. static_assert(std::is_same_v<meta::collect_list_t<a, std::index_sequence<1,1>>, meta::list<int, int>>);
  17. static_assert(std::is_same_v<meta::collect_list_t<a, std::index_sequence<1,2,3,0,0>>,
  18. meta::list<int, short, char, long, long>>);
  19. using b = some_other_list<int, char, short>;
  20. static_assert(meta::list_size_v<b> == 3);
  21. static_assert(std::is_same_v<meta::list_element_t<0, b>, int>);
  22. static_assert(std::is_same_v<meta::list_element_t<1, b>, char>);
  23. static_assert(std::is_same_v<meta::list_element_t<2, b>, short>);
  24. static_assert(std::is_same_v<meta::collect_list_t<b, std::index_sequence<1,2>>, some_other_list<char, short>>);
  25. static_assert(std::is_same_v<meta::collect_list_t<b, std::index_sequence<1>>, some_other_list<char>>);
  26. static_assert(std::is_same_v<meta::collect_list_t<b, std::index_sequence<>>, some_other_list<>>);
  27. static_assert(std::is_same_v<meta::collect_list_t<b, std::index_sequence<1,1>>, some_other_list<char, char>>);
  28. static_assert(std::is_same_v<meta::collect_list_t<b, std::index_sequence<1,2,0,0>>,
  29. some_other_list<char, short, int, int>>);
  30. return 0;
  31. }