提升三次埃尔米特插值"requires template argument list"



我正试图使用boost库中的三次Hermite插值来插值非等间距数据。然而,从文档中实现该示例会产生错误"0";C2955:"boost::math::interpolators::cubic_hermite":使用类模板需要模板参数列表"。

这是我的代码:

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时生成的。出现错误的原因可能是什么?

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

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

最新更新