diff --git a/source/simple/support/carcdr.hpp b/source/simple/support/carcdr.hpp index 875dc25fe88d3b9a308a7ee764714cdc55c2be84..37804b06e078d205a241d3f612b29b87257fc948 100644 --- a/source/simple/support/carcdr.hpp +++ b/source/simple/support/carcdr.hpp @@ -6,7 +6,7 @@ namespace simple::support { - using std::size_t; + using std::size_t; // TODO: hmm... template <typename Int, Int... Values> using lisp_list = std::integer_sequence<Int, Values...>; @@ -57,6 +57,32 @@ namespace simple::support return carcdr<List>::car; }(); + // TODO: not car cdr anymore, move + template <typename IntSec, typename OtherIntSec> + struct concat_seq; + + template <typename Int, Int... ones, Int... others> + struct concat_seq<std::integer_sequence<Int, ones...>, std::integer_sequence<Int,others...>> + { + using type = std::integer_sequence<Int, ones..., others...>; + }; + + template <typename A, typename B> + using concat_seq_t = typename concat_seq<A,B>::type; + + + template <typename Int, Int, typename Seq> + struct offset_seq; + + template <typename Int, Int offset, Int... Is> + struct offset_seq<Int, offset, std::integer_sequence<Int, Is...>> + { + using type = std::integer_sequence<Int, (Is + offset)...>; + }; + + template <typename Int, Int offset, typename Seq> + using offset_seq_t = typename offset_seq<Int, offset, Seq>::type; + } // namespace simple::support #endif /* end of include guard */ diff --git a/unit_tests/carcdr.cpp b/unit_tests/carcdr.cpp index 4ac8f2a5f98fe15453d71a34c4ab563e3f2d1879..1b60721497d0ffb472006241cb7d10e81816bfea 100644 --- a/unit_tests/carcdr.cpp +++ b/unit_tests/carcdr.cpp @@ -2,6 +2,9 @@ using namespace simple::support; +template <int... Is> +using iseq = std::integer_sequence<int, Is...>; + int main() { using ints = lisp_list<int, -1, 10, 13, 999>; @@ -14,5 +17,14 @@ int main() static_assert(std::is_same_v<cdr<cdr<cdr<cdr<ints>>>>, lisp_list<int>>); + + static_assert(std::is_same_v< + concat_seq_t<iseq<1,2>, iseq<3,4,5>>, + iseq<1,2,3,4,5>>); + + static_assert(std::is_same_v< + offset_seq_t<int, -3, iseq<1,2,3>>, + iseq<-2,-1,0>>); + return 0; }