
Hello, how can I make the snipped more generic in that way, that I can use it with different data members, e.g. as template argument the &actions::m_data::text data address. Then I could write e.g. set_generic<&actions::m_data::text, std::string> set_text; Thanks, Olaf ---8<--- #include <iostream> #include <string> struct data { std::string text; }; struct actions { explicit actions(data& d) : set_text( *this ), m_data( d ) { } template<typename T> struct set_generic { explicit set_generic( actions& actions ) : self( actions ) { } void operator()(const T& data) const { self.m_data.text = data; } private: actions& self; }; set_genericstd::string set_text; set... data& m_data; }; using namespace std; int main() { data d; actions a( d ); a.set_text( "Hello" ); cout << d.text << endl; } --->8---

AMDG Olaf Peter wrote:
how can I make the snipped more generic in that way, that I can use it with different data members, e.g. as template argument the &actions::m_data::text data address. Then I could write e.g.
set_generic<&actions::m_data::text, std::string> set_text;
template
participants (2)
-
Olaf Peter
-
Steven Watanabe