Skip to content

Commit

Permalink
Add Kumi interface to kwk::position
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainJoube committed Oct 2, 2024
1 parent b0e3105 commit de74cf5
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
19 changes: 19 additions & 0 deletions include/kwk/utility/position.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,24 @@ namespace kwk
}
return os << ")";
}

// === Kumi interface ===
using is_product_type = void;

template<std::size_t I>
friend constexpr auto const& get(position const& p) noexcept
{
return p.pos[I];
}

template<std::size_t I>
friend constexpr auto& get(position& p) noexcept
{
return p.pos[I];
}
// ^^^ Kumi interface ^^^
};
}

template<std::size_t Sz> struct std::tuple_size<kwk::position<Sz>> : std::integral_constant<std::size_t, Sz> {};
template<std::size_t Sz> struct std::tuple_element<Sz, kwk::position<Sz>> { using type = kwk::position<Sz>::position_type; };
48 changes: 47 additions & 1 deletion test/algorithm/algos/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//======================================================================================================================
#include <kwk/utility/position.hpp>
#include "test.hpp"
#include <kwk/detail/kumi.hpp>

// for_each 1D - 4D

Expand All @@ -31,8 +32,53 @@ TTS_CASE("Check for kwk::position(std::array)")
std::stringstream ss;
ss << p1;
TTS_EQUAL(ss.str(), std::string{"position<3>(0, 1, 2)"});
};


};
// === Kumi interface ===
// Every test fails or raise a compile-time error
// TTS_CASE("Check adapted types model kumi::product_type concept")
// {
// TTS_EXPECT ( kumi::product_type<kwk::position<8>> );
// TTS_EXPECT ( (kumi::product_type<std::array<int,4>> ));
// TTS_EXPECT_NOT( (kumi::product_type<std::pair<int,float>>));
// };

// TTS_CASE("Check adapted type behave like a product_type")
// {
// auto r = kumi::apply( [](auto... x) { return (x + ...); }, kwk::position<4>{{2, 4, 7, 12}});
// TTS_EQUAL(r, 25);

// auto zz = kumi::zip( kwk::position<4>{{11, 12, 13, 14}}, kwk::position<4>{{21, 22, 23, 24}});
// TTS_EQUAL ( zz, ( kumi::tuple { kumi::tuple{11, 21}
// , kumi::tuple{12, 22}
// , kumi::tuple{13, 23}
// , kumi::tuple{14, 24}
// })
// );

// auto cc = kumi::cat( kwk::position<2>{{11, 12}}, kwk::position<2>{{13, 14}});
// TTS_EQUAL ( cc, ( kumi::tuple {11, 12, 13, 14}) );
// };


// =======

// Generic Kumi tests, unrelated with kwk::position (these tests are passing)
// TTS_CASE("Check adapted external type behave like a product_type")
// {
// auto r = kumi::apply( [](auto... x) { return (x + ...); }, std::array{1,2,5,4});
// TTS_EQUAL(r, 12);

// auto zz = kumi::zip( std::array{1,2,5}, std::array{0.1,2.3,4.5});
// TTS_EQUAL ( zz, ( kumi::tuple { kumi::tuple{1 , 0.1 }
// , kumi::tuple{2 , 2.3 }
// , kumi::tuple{5 , 4.5 }
// })
// );

// auto cc = kumi::cat( std::array{1,2,5}, std::array{0.1,2.3,4.5} );
// TTS_EQUAL ( cc, ( kumi::tuple {1, 2, 5, 0.1, 2.3, 4.5}) );
// };


0 comments on commit de74cf5

Please sign in to comment.