Boost logo

Boost :

Subject: Re: [boost] Preprocessor directive for a sequence that differs only in datatype
From: Larry Evans (cppljevans_at_[hidden])
Date: 2017-07-11 11:17:42

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 <<dummy<< std::endl;
using fptr=void (*)(std::size_t);
fptr printers[]=
{ print_column<int>
, print_column<float>
int main()
   unsigned ncol_=2;
   for(unsigned i=0; i<ncol_; ++i)
   return 0;

Boost list run by bdawes at, gregod at, cpdaniel at, john at