lager
lager copied to clipboard
lager::with() and lager::reader<tuple<...>> behave in a non-symmetrical way
I have a feeling like there is some bug in mapping readers holding a tuple. It seems to be impossible to map-unzip them into a normal function. Here is a code example:
#include <zug/tuplify.hpp>
#include <zug/transducer/zip.hpp>
#include <zug/transducer/unzip.hpp>
TEST_CASE("tuple unfolding")
{
auto callback = [] ([[maybe_unused]] int x, [[maybe_unused]] std::string y) {
return std::to_string(x) + "-" + y;
};
auto callback_tuple = [] ([[maybe_unused]] std::tuple<int, std::string> x) {
return std::to_string(std::get<0>(x)) + "-" + std::get<1>(x);
};
state<int, automatic_tag> value1{7};
state<std::string, automatic_tag> value2{"value"};
reader<std::string> converted_value{with(value1, value2).map(callback)};
reader<std::string> converted_value2{with(value1, value2).xform(zug::zip).map(callback_tuple)};
CHECK(converted_value.get() == "7-value");
CHECK(converted_value2.get() == "7-value");
reader<std::tuple<int, std::string>> tuplified{with(value1, value2)};
// BUG: Fails to compile!
// reader<std::string> converted_from_tuple{tuplified.xform(zug::unzip).map(callback)};
reader<std::string> converted_from_tuple2{tuplified.map(callback_tuple)};
//CHECK(converted_from_tuple.get() == "7-value");
CHECK(converted_from_tuple2.get() == "7-value");
}
It is possible to map a with
-expression to both, tuple-style and unfolded callback, but it is impossible to map a tuple-containing reader to it.
Full unittest is in this commit: https://github.com/arximboldi/lager/commit/ba8fe64863c1aecefd2eb1c11629943ba5c7e82a