From 11621a13adb0e34cddc8d6b1507251baf7f1c5aa Mon Sep 17 00:00:00 2001 From: tk Date: Sat, 13 Mar 2021 21:44:42 +0100 Subject: [PATCH] add check the source still compiles with -std=c++98 --- examples/Makefile | 5 ++++- examples/tests/simple_demo_c98.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 examples/tests/simple_demo_c98.cpp diff --git a/examples/Makefile b/examples/Makefile index 6b4041c..4393b87 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -16,7 +16,7 @@ LFLAGS= PROGS=simple_demo plot plot_avg_preserv plot_parametric plot_bspline PROGS_ALGLIB=plot_alglib bench -PROGS_TESTS=tests/unit_tests tests/compile_units +PROGS_TESTS=tests/unit_tests tests/compile_units tests/simple_demo_c98 all: ${PROGS} more: ${PROGS_ALGLIB} @@ -37,9 +37,12 @@ plot_bspline: plot_bspline.o tests/compile_units: tests/compile_units.o tests/myfunc1.o tests/myfunc2.o ${CC} $? -o $@ +tests/simple_demo_c98: tests/simple_demo_c98.cpp ../src/spline.h + ${CC} -Wall -Wextra -Werror -I../src -std=c++98 $< -o $@ tests/unit_tests: tests/unit_tests.o ${CC} $< -o $@ -lboost_unit_test_framework + %.o: %.cpp ../src/spline.h ${CC} ${CFLAGS} -c $< -o $@ diff --git a/examples/tests/simple_demo_c98.cpp b/examples/tests/simple_demo_c98.cpp new file mode 100644 index 0000000..48c36a5 --- /dev/null +++ b/examples/tests/simple_demo_c98.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +#include "spline.h" + +int main(int argc, char** argv) +{ + double x=0.0; + if(argc>1) + x = atof(argv[1]); + + std::vector X(5), Y(5); + X[0]=-0.1; X[1]=0.4; X[2]=1.2; X[3]=1.8; X[4]=2.0; + Y[0]=0.1; Y[1]=0.7; Y[2]=0.6; Y[3]=1.1; Y[4]=0.9; + + + tk::spline s1(X,Y); // defaults to C^2 cubic spline (spline::cspline) + tk::spline s2(X,Y,tk::spline::cspline_hermite); + tk::spline s3(X,Y,tk::spline::linear); + + printf("spline(%.3f): cubic (C^2) = %.3f, cubic hermite = %.3f, linear = %.3f\n", x, s1(x), s2(x), s3(x)); + + return EXIT_SUCCESS; +}