Boost cubic Hermite interpolation "requires template argument list"

Viewed 170

I am attempting to use cubic Hermite interpolation from the boost library in order to interpolate non-equispaced data. However, implementing the example from the documentation produces the error "C2955: 'boost::math::interpolators::cubic_hermite': use of class template requires template argument list".

Here is my code:

CMakeLists.txt

cmake_minimum_required(VERSION 3.18)

project(CubicHermiteTest LANGUAGES CXX)

set(Boost_USE_STATIC_LIBS        ON)
set(Boost_USE_MULTITHREADED      ON)
set(Boost_USE_STATIC_RUNTIME    OFF)
#set(Boost_DEBUG ON)
set(BOOST_ROOT "C:/local/boost_1_76_0/boost" )
set(BOOST_INCLUDEDIR "C:/local/boost_1_76_0" )
set(BOOST_LIBRARYDIR "C:/local/boost_1_76_0/lib64-msvc-14.2" )

find_package(Boost 1.76.0 REQUIRED)

add_executable(CubicHermiteTest
  main.cpp
)
target_link_libraries(CubicHermiteTest Boost::boost)

main.cpp

#include <iostream>
#include <vector>
#include <boost/math/interpolators/cubic_hermite.hpp>

int main()
{
    std::vector<double> x{1, 5, 9 , 12};
    std::vector<double> y{8,17, 4, -3};
    std::vector<double> dydx{5, -2, -1,2};
    using boost::math::interpolators::cubic_hermite;
    auto spline = cubic_hermite(std::move(x), std::move(y), std::move(dydx));
    // evaluate at a point:
    double z = spline(3.4);
    // evaluate derivative at a point:
    double zprime = spline.prime(3.4);
    
    std::cout << zprime << '\n';
}

The error is generated when calling cubic_hermite. What could be the reason for the error?

1 Answers

The code example suggests that you want to use class template argument deduction (for the RandomAccessContainer template parameter of cubic_hermite). Either make sure that your compiler is working with the C++17 standard (as no earlier standard supports this feature) or explicitly specify the template argument, such as

auto spline = cubic_hermite<decltype(x)>(std::move(x), std::move(y), std::move(dydx));
Related