arximboldi / lager

C++ library for value-oriented design using the unidirectional data-flow architecture — Redux for C++
https://sinusoid.es/lager/
MIT License
700 stars 66 forks source link

Basic Example doesn't compile on MSVC '17 #206

Open collinschupman opened 1 month ago

collinschupman commented 1 month ago

I'm trying to compile a basic example, very close to what's presented in the examples folder on Windows w/ MSVC '17:

struct model
{
    int value = 0;
};

struct increment_action {};
struct decrement_action {};
struct reset_action { 
    int new_value = 0;
};

using action = std::variant<increment_action, decrement_action, reset_action>;

auto store = lager::make_store<action >(
       model{}, lager::with_manual_event_loop{});

This basic store init fails with error:

Severity    Code    Description Project File    Line    Suppression State   Details
Error   C3200   'lager::detail::reader_node<T>': invalid template argument for template parameter 'Base', expected a class template redacted    redacted\lib\lager\store.hpp    40      

I'm not entirely sure what the error is but store_node_base seems to have issue deducing the types it needs correctly.

TheCoconutChef commented 1 month ago

I don't think this is a MSVC issue. You don't have an update function.

Try adding:

model update(model m, action a) { return m; }

Edit

Note that, as far as I can tell, there isn't necessarily a location in the lager doc that specifies explicitly that, by default, the make_store function expects to see an update function of an appropriate signature in order to work. However, it does show an example of the with_reducer enhancer here. This latter enhancer allow for more flexibility in the definition of your update function. In particular, it can be a class.

collinschupman commented 1 month ago

@TheCoconutChef I forgot to add that code in my original post but I did have that update function. I just tested again with the update function and confirmed I am getting the same error. I read on another post people having better luck with C++20 so I switched to that and am now facing the same issue described here: https://github.com/arximboldi/lager/issues/126#issuecomment-1942734127

arximboldi commented 1 month ago

I can't use MSVC myself, but contributions fixing these issues more than welcome!