samedi 27 juillet 2019

Custom Functions in C++ Template

If I am using a C++ class with a template parameter of an int like:

template<int width> class ap_uint { ... }

then I understand that I can create specific definitions from this type of certain widths like:

typedef ap_uint<72> data_t;

However, if I wanted to say define a constant and pass that in, what are my options (other than define)? Say something like this:

#define WIDTH 72
typedef ap_uint<WIDTH> data_t;
typedef ap_uint<WIDTH / 8> mask_t; // Does this even work?

Further would it be possible to define a function or use an existing one in the template parameter selection? Something like this:

#define SIZE 1024
typedef ap_uint<ceil(log(SIZE, 2))> addr_t;

I am fine having to write the functions myself, if that is even possible.

Aucun commentaire:

Enregistrer un commentaire