On 07/11/2017 06:17 AM, Larry Evans via Boost wrote:
On 07/11/2017 03:09 AM, Rishabh Arora via Boost wrote:
Thank you, Gavin Lambert.
I don't think any of the preprocessor directives will work then? because
type cannot be determined at comile time? Is there any other way to do
that?
What about replacing the switch with an index into a vector
of function pointers? Something like:
#include <iostream>
template < class T >
void print_column(std::size_t col) {
T dummy;
std::cout <
More specifically:
#ifdef USE_PRINTER_TYPES
template
struct printers
{
using fptr = void(data_frame::*)(size_t);
static constexpr fptr _[sizeof...(Types)]=
{ &data_frame::print_column<Types>...
};
};
using printer_types=printers;
#endif//USE_PRINTER_TYPES
Then, use printer_types in the data_frame::print function as:
std::cout << "[" << column_headers_(i) << "]" << ": ";
auto const itype=base_::operator[](column_headers_(i)).type();
#ifdef USE_PRINTER_TYPES
printer_types::fptr printer=printer_types::_[itype];
(this->*printer)(i);
#else
switch(itype) {
.
.
.
#endif//USE_PRINTER_TYPES
HTH.
-regards,
Larry