I am trying to write a print function for my template class:
struct ColumnKey;
template <class Type, class Key = ColumnKey>
class Column {
protected:
std::shared_ptr<Type> doGet() {
std::lock_guard<std::mutex> lock(mutex_);
return std::make_shared<Type>(value_);
}
void doSet(const std::shared_ptr<Type> &value) {
std::lock_guard<std::mutex> lock(mutex_);
value_ = *value;
}
private:
Type value_;
std::mutex mutex_;
};
template<class... Columns>
class Table : private Columns... {
public:
template<class Type, class Key = ColumnKey>
std::shared_ptr<Type> get() {
return Column<Type, Key>::doGet();
}
template<class Type, class Key = ColumnKey>
void set(const std::shared_ptr<Type> &value) {
Column<Type, Key>::doSet(value);
}
std::string get_table_row() {
return "hello_row";
}
};
I want to create a function get_table_row
in class Table
, which returns columnA + "," + columnB + "," + ..
I am trying to write in this way, but getting compilation errors. Can somebody point the mistake in my approach?
template <class Column<class Type, class Key = ColumnKey>>
std::string get_row() {
return std::to_string( *Column<Type, Key>::doGet() );
}
template <class Column<class Type, class Key = ColumnKey>, class... Columns>
std::string get_row() {
return ( std::to_string(*Column<Type, Key>::doGet()) + "," + Columns.get_row() );
}
I am struggling to do that, can anybody guide me ?