提升三次 Hermite 插值 "requires template argument list"

Boost cubic Hermite interpolation "requires template argument list"

我正在尝试使用 boost 库中的三次 Hermite 插值来插值非等距数据。但是,从 documentation 实施示例会产生错误“C2955:'boost::math::interpolators::cubic_hermite':使用 class 模板需要模板参数列表”。

这是我的代码:

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';
}

调用cubic_hermite时出现错误。错误的原因可能是什么?

代码示例建议您使用 class 模板参数推导(对于 cubic_hermiteRandomAccessContainer 模板参数)。确保您的编译器使用 C++17 标准(因为没有早期标准支持此功能)或显式指定模板参数,例如

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