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

Upgrade videos, adn some coding style.

parent 4684ad1f
......@@ -4,10 +4,10 @@
template < typename T >
class Ref {
public :
Ref( T & data ) { pdata = &data ; }
void operator=( T data ) { *pdata = data ; }
Ref( T & data ) { m_pdata = &data ; }
void operator=( T data ) { *m_pdata = data ; }
private :
T * pdata ;
T * m_pdata ;
} ;
template < typename T >
......
......@@ -5,10 +5,10 @@ template < typename T >
class Ref
{
public :
Ref( T & data ) : data_(data) {}
void operator=( T data ) { data_ = data ; }
Ref( T & data ) : m_data(data) {}
void operator=( T data ) { m_data = data ; }
private :
T & data_ ;
T & m_data ;
} ;
template < typename T >
......
......@@ -11,10 +11,10 @@ template < typename T >
class Ref
{
public :
Ref( T data ) { data_ = data ; }
void operator=( T data ) { data_ = data ; }
Ref( T data ) { m_data = data ; }
void operator=( T data ) { m_data = data ; }
private :
T data_ ;
T m_data ;
} ;
template < typename T >
......
......@@ -4,20 +4,20 @@
#include <iostream>
#include <cmath>
int main ( int argc, char * argv[] )
int main()
{
int dim {atoi(argv[1])} ;
int degree {atoi(argv[2])} ;
int const DIM {10} ;
int const DEGREE {5} ;
// generate random input
std::vector<double> input(dim) ;
std::vector<double> input(DIM) ;
std::for_each(input.begin(),input.end(),[]( double & value )
{ value = ((2.*std::rand())/RAND_MAX-1.) ; }) ;
// compute output
std::vector<double> output(dim) ;
std::transform(input.begin(),input.end(),output.begin(),[degree]( double x )
{ return std::pow(x,degree) ; }) ;
std::vector<double> output(DIM) ;
std::transform(input.begin(),input.end(),output.begin(),[DEGREE]( double x )
{ return std::pow(x,DEGREE) ; }) ;
// print sum
std::cout<<std::accumulate(output.begin(),output.end(),0.)<<std::endl ;
......
......@@ -4,7 +4,7 @@
class MyData
{
public :
MyData( int data ) : m_data(data)
MyData( int data ) : m_data {data}
{ std::cout<<"MyData::MyData("<<m_data<<")"<<std::endl ; }
int data() const { return m_data ; }
~MyData() { std::cout<<"MyData::~MyData("<<m_data<<")"<<std::endl ; }
......
......@@ -19,7 +19,7 @@ void display( std::shared_ptr<MyData> data_ptr )
template <typename T, typename... 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()
{
......
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