Commit 98935baf authored by CHAMONT David's avatar CHAMONT David
Browse files

Upgrade videos, adn some coding style.

parent 4684ad1f
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
template < typename T > template < typename T >
class Ref { class Ref {
public : public :
Ref( T & data ) { pdata = &data ; } Ref( T & data ) { m_pdata = &data ; }
void operator=( T data ) { *pdata = data ; } void operator=( T data ) { *m_pdata = data ; }
private : private :
T * pdata ; T * m_pdata ;
} ; } ;
template < typename T > template < typename T >
......
...@@ -5,10 +5,10 @@ template < typename T > ...@@ -5,10 +5,10 @@ template < typename T >
class Ref class Ref
{ {
public : public :
Ref( T & data ) : data_(data) {} Ref( T & data ) : m_data(data) {}
void operator=( T data ) { data_ = data ; } void operator=( T data ) { m_data = data ; }
private : private :
T & data_ ; T & m_data ;
} ; } ;
template < typename T > template < typename T >
......
...@@ -11,10 +11,10 @@ template < typename T > ...@@ -11,10 +11,10 @@ template < typename T >
class Ref class Ref
{ {
public : public :
Ref( T data ) { data_ = data ; } Ref( T data ) { m_data = data ; }
void operator=( T data ) { data_ = data ; } void operator=( T data ) { m_data = data ; }
private : private :
T data_ ; T m_data ;
} ; } ;
template < typename T > template < typename T >
......
...@@ -4,20 +4,20 @@ ...@@ -4,20 +4,20 @@
#include <iostream> #include <iostream>
#include <cmath> #include <cmath>
int main ( int argc, char * argv[] ) int main()
{ {
int dim {atoi(argv[1])} ; int const DIM {10} ;
int degree {atoi(argv[2])} ; int const DEGREE {5} ;
// generate random input // generate random input
std::vector<double> input(dim) ; std::vector<double> input(DIM) ;
std::for_each(input.begin(),input.end(),[]( double & value ) std::for_each(input.begin(),input.end(),[]( double & value )
{ value = ((2.*std::rand())/RAND_MAX-1.) ; }) ; { value = ((2.*std::rand())/RAND_MAX-1.) ; }) ;
// compute output // compute output
std::vector<double> output(dim) ; std::vector<double> output(DIM) ;
std::transform(input.begin(),input.end(),output.begin(),[degree]( double x ) std::transform(input.begin(),input.end(),output.begin(),[DEGREE]( double x )
{ return std::pow(x,degree) ; }) ; { return std::pow(x,DEGREE) ; }) ;
// print sum // print sum
std::cout<<std::accumulate(output.begin(),output.end(),0.)<<std::endl ; std::cout<<std::accumulate(output.begin(),output.end(),0.)<<std::endl ;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
class MyData class MyData
{ {
public : public :
MyData( int data ) : m_data(data) MyData( int data ) : m_data {data}
{ std::cout<<"MyData::MyData("<<m_data<<")"<<std::endl ; } { std::cout<<"MyData::MyData("<<m_data<<")"<<std::endl ; }
int data() const { return m_data ; } int data() const { return m_data ; }
~MyData() { std::cout<<"MyData::~MyData("<<m_data<<")"<<std::endl ; } ~MyData() { std::cout<<"MyData::~MyData("<<m_data<<")"<<std::endl ; }
......
...@@ -19,7 +19,7 @@ void display( std::shared_ptr<MyData> data_ptr ) ...@@ -19,7 +19,7 @@ void display( std::shared_ptr<MyData> data_ptr )
template <typename T, typename... Args> template <typename T, typename... Args>
std::shared_ptr<T> make_ptr( Args... args ) std::shared_ptr<T> make_ptr( Args... args )
{ return std::shared_ptr<T>(new T(args...)) ; } { return std::make_shared<T>(args...) ; }
int main() int main()
{ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment