Skip to content

Commit

Permalink
updated to eliminate deprecated stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
lformaggia committed Feb 23, 2024
1 parent dda4405 commit 1dd570a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 24 deletions.
5 changes: 3 additions & 2 deletions Examples/src/Bindings/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ foo(int &a)
*
* @param a
*/

void
foo(const int &a)
{
Expand Down Expand Up @@ -146,9 +147,9 @@ main()
std::cout << "foo does not implement overloads with rvalue-references\n";
std::cout << "calling foo(25) (a literal):" << std::endl;
foo(25); // foo(const int&)
std::cout << "calling foo(a) (a is int, a lvalue):" << std::endl;
std::cout << "calling foo(a) (a is int, a non-const lvalue):" << std::endl;
foo(a); // foo(int&)
std::cout << "calling foo(b) (b is int&, a lvalue):" << std::endl;
std::cout << "calling foo(b) (b is int&, a non-const lvalue):" << std::endl;
foo(b); // foo(int&)
std::cout << "calling foo(createFive()), I am passing a rvalue:"
<< std::endl;
Expand Down
7 changes: 3 additions & 4 deletions Examples/src/Functors/functors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ Sqrt5::operator()(double a) const
// df =5*y^4
if(a == 0.0)
return 0.0;
auto der = [](double const x) { return 5 * x * x * x * x; };
auto resid = [&a](double const x) { return x * x * x * x * x - a; };
auto phi =[&a](double const x) { return (a/x/x/x/x -x ) / 5; };
auto err = 2 * tolerance;
unsigned int iter = 0;
auto x = x0;
while((err > tolerance) && (iter < maxiter))
{
// I should check if der=0 but here I avoid for simplicity
auto step = -resid(x) / der(x);
// I should
auto step = phi(x);
err = std::abs(step);
x += step;
++iter;
Expand Down
22 changes: 6 additions & 16 deletions Examples/src/Functors/functors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@ namespace myfunctors
{
/*!
*
* A functor (object function) that takes a single argument is also called a
* A unary functor.
*
* It is good practice to inherit from std::unary_function,
* so that it complies with the unary functors in the
* standard library (It is not compulsory though,! you can do without)
* This object function computes fifth root of a by Newton method. Definition in
* @brief Computes the fitfh root of a number by Newton method
*
* A functor (object function) that takes a single argument is also called aunary functor.
* This object function computes fifth root of a by Newton method up to 10^-6 precision. Definition in
* the cpp file
*/
struct Sqrt5 : public std::unary_function<double, double>
struct Sqrt5
{
double operator()(double a) const;
//! max number of iterations (default=100)
Expand All @@ -44,15 +41,8 @@ struct Sqrt5 : public std::unary_function<double, double>
that returns true if the value passed is greater than a value that
may be changed run time.
Since all methods are simple I will define them in class (no need
of cpp file) It is a unary function so I inherit from the
corresponding std class (not strictly needed, but it makes it
complient with the stl rules). Inheriting publicly from
unary_function provides two typedef members argument_type and
result_type
*/
class Isgreater : public std::unary_function<double, bool>
class Isgreater
{
public:
Isgreater(double const &a) : my_value{a} {};
Expand Down
3 changes: 2 additions & 1 deletion Examples/src/Functors/main_functors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
#include <iomanip>
#include <iostream>
#include <vector>
#include <cmath>
int
main()
{
using namespace myfunctors; // only to simplify things
//! Creating an object
Sqrt5 sqrt5;
// comput fifth root of five
std::cout << std::setprecision(15) << "sqrt5(5)=" << sqrt5(5) << std::endl;
std::cout << std::setprecision(15) << "Exact value of fifth root of 5=" << std::pow(5,1./5.) << std::endl;
// we have set a larger precision to see more digits. The setting
// can be brought back to the default by
// std::cout<<std::defaultfloat;
Expand Down
2 changes: 1 addition & 1 deletion Examples/src/Utilities/test_cppversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ int
main()
{
std::string version;
std::cout<<"version sting is _cplusplus\n";
std::cout<<"version id is "<< __cplusplus<<"\n";
if(Utilities::is_cxx11())
version = "C++11";
else if(Utilities::is_cxx14())
Expand Down

0 comments on commit 1dd570a

Please sign in to comment.