In c++11, the current behavior returns a warning:
int arr[3] = { 0.0f, 1.0f, 2.0f};
Based on the following post, I was able to create
template <class T, class ... Ts>
std::array<T, sizeof...( Ts )> make_non_narrowed_arr(Ts&& ... ts)
{
return{ { static_cast<T>( ts )... } };
}
auto arr = make_not_narrowed_arr<int>(0.0f, 1.0f, 2.0f );
But I would like the return to be a classic c-array, but I was not able to achieve it. So far I tried those, but none are compiling.
template<class T, class ... Ts>
T[sizeof...( Ts )] make_non_narrowed_arr(Ts&& ... ts) {...};
template<class T, std::size_t N, class ... Ts>
T[N] make_non_narrowed_arr(Ts&& ... ts) {...};
template<class T, class ... Ts>
T* make_non_narrowed_arr(Ts&& ... ts) {...};
I want to do the following to have a warning free program, without suppressing them in compiler. So this post is not a solution for me either.
And I can't change to std::array for that specific usage since it need to be use afterward in a c routine that use T* only.
EDIT: Here a sample (not the exact code 100%) of what I have as code, and what I want to change.
The problem with the function is that based on image type and channel, I perform call to IPP routine, and I provide generic float* as input to the wrapper routine.
void threshold(Image img, Image dst, float* th)
{
// Sanitty ckeck on image, and bla bla...
// Perform the call to ipp
IppStatus sts = (IppStatus)0;
switch(img.nbChan)
{
case 1:
{
switch(img.type)
{
case BYTE:
{
Ipp8u arr[1] = {Th[0] };
sts = ippiThreshold_GTVal_8u_C1R(img.data, img.pitch, dst.data, dst.pitch, arr);
break;
}
case FLOAT:
{
Ipp32f arr[1] = {Th[0] };
sts = ippiThreshold_GTVal_32f_C1R(img.data, img.pitch, dst.data, dst.pitch, arr);
break;
}
}
break;
}
case 3:
{
switch(img.type)
{
case BYTE:
{
Ipp8u arr[3] = {Th[0], Th[1], Th[2]};
sts = ippiThreshold_GTVal_8u_C3R(img.data, img.pitch, dst.data, dst.pitch, arr);
break;
}
case FLOAT:
{
Ipp32f arr[3] = {Th[0], Th[1], Th[2]};
sts = ippiThreshold_GTVal_32f_C3R(img.data, img.pitch, dst.data, dst.pitch, arr);
break;
}
}
break;
}
}
}
T*only." Are you not able to usestd::array<T, N>::data()?std::arrayor wrap the C-style array in a struct.std::arrayto a C routine. Usestd::array::data()or even&arr[0]would do (but the.dataversion is better)