Reputation: 125
Lets say I have different classes and each class has its own header variable known at compile time . I am using constexpr std::array<>
for this. And each class has variable data
which will be known at runtime . Now I need to create a common class Table
which will accept headers
& data
of different classes and create table UI.
How can I write a function which accepts std::array
of different size ? I am using std::array
because it can be used with constexpr
for example ,
using columWidth = int;
class student{
constexpr std::array<std::pair<std::string_view, columWidth>, 2> mHeader=
{
{"Name", 150}, //name column has width 150
{"id", 100} // id column has width 100
}; //total 2 columns . so array size is 2.
std::vector<std::pair<std::string, int>> data;
};
class teacher{
constexpr std::array<std::pair<std::string_view, columWidth>, 3> mHeader=
{
{"Name", 150},
{"Degree", 100},
{"University", 100},
};
std::vector<std::pair<std::string, int>> data;
};
class Table
{
public:
void setHeader(); //this should accept std::array of different size, how ?
void createTable();
void changeTableIndex(int index);
private:
mHeader ; // what should be the type of this header ? and how to receive and store this header ?
}
I don't want to make the whole Table
class as template because it has other member functions as well .
Upvotes: -1
Views: 113