C ++ 0x interference output type with boost :: enable_if

I am trying to write a general filtering function that performs linear interpolation at a given coordinate of a sample in a multidimensional array (arbitrary rank). To do this, I need a recursive function template that scans all dimensions of the array until it reaches a value and the type associated with it. I use boost :: enable_if to determine when to stop iteration over dimensions. It works fine until I try to “percolate” the return value / type to the topmost function. For this purpose I tried to use output like C ++ 0x, but it does not seem to mix with boost :: enable_if.

I highlighted the problem until the following:

template< typename T, std::size_t I >
auto test(const T &t) -> typename boost::enable_if_c< (I == 0), typename T::value_type >::type
{
    return t[0];
}

template< typename T, std::size_t I >
auto test(const T &t) -> typename boost::enable_if_c< (I > 0), decltype(test< T, I - 1 >(T())) >::type
{
    return test< typename T::value_type, std::size_t(I - 1) >(t[0]);
}

The compiler (GCC 4.6) complains about the following code:

typedef std::array< std::array< float, 1 >, 1 > myarray;
myarray ma;
std::cout << typeid (test< myarray, 1 >(ma)).name() << std::endl;

Error message:

error: conversion from 'boost::enable_if_c<true, float>::type' to non-scalar type 'boost::enable_if_c<true, std::array<float, 1u> >::type' requested

, decltype test < T, I > , test < T, - 1 > . , ? , , ...

+3
1

, T() ( T) decltype. . , return , decltype, - .

template< typename T, std::size_t I >
auto test(const T &t) -> typename boost::enable_if_c< (I > 0), decltype(test< T, I - 1 >(T())) >::type
{
    return test< typename T::value_type, std::size_t(I - 1) >(t[0]);
}

decltype: test<T

return expression: test< typename T::value_type

, , decltype, , , return.

: , rvalues, lvalues, , .

+4

Source: https://habr.com/ru/post/1786798/


All Articles