Skip to content

Commit

Permalink
add check the source still compiles with -std=c++98
Browse files Browse the repository at this point in the history
  • Loading branch information
tk committed Mar 13, 2021
1 parent 42f8e81 commit 11621a1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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 $@

Expand Down
24 changes: 24 additions & 0 deletions examples/tests/simple_demo_c98.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <cstdio>
#include <cstdlib>
#include <vector>
#include "spline.h"

int main(int argc, char** argv)
{
double x=0.0;
if(argc>1)
x = atof(argv[1]);

std::vector<double> 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;
}

0 comments on commit 11621a1

Please sign in to comment.