I
I
IliaNeverov2021-08-03 15:18:51
C++ / C#
IliaNeverov, 2021-08-03 15:18:51

How to find out the size of each element of the variable templates separately?

The variables float a, float a 2, MyClass a3, bool a4 were passed to the function instead of the parameter package. How can I find out the size of each of these variables in the function itself?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniel, 2021-08-03
@IliaNeverov

C++17 is required, for C++11 this is possible through template recursion. If necessary, I will explain how to do it.

template<typename ...Arg>
auto foo(){


    std::vector<unsigned int> _sizeofs;// массив с размерами каждого элемента
    ((_sizeofs.push_back(sizeof(Arg))),...);



}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question