C++ Template Metaprogramming
Solutions to the exercises throughout the book
Loading...
Searching...
No Matches
exercise_3_5::section_3_1 Namespace Reference

Modification of algorithms from Chapter 3, Section 1. More...

Classes

struct  divide_dimensions
 Divide all elements of two dimension sequences. More...
 
struct  multiply_dimensions
 Multiply all elements of two dimension sequences. More...
 
class  quantity
 A numerical quanitity with intrinsic dimensions. More...
 

Typedefs

typedef boost::mpl::vector_c< int, 0, 0, 0, 0, 0, 0, 0 > scalar
 
typedef boost::mpl::vector_c< int, 1, 0, 0, 0, 0, 0, 0 > mass
 
typedef boost::mpl::vector_c< int, 0, 1, 0, 0, 0, 0, 0 > length
 
typedef boost::mpl::vector_c< int, 0, 0, 1, 0, 0, 0, 0 > time
 
typedef boost::mpl::vector_c< int, 0, 0, 0, 1, 0, 0, 0 > charge
 
typedef boost::mpl::vector_c< int, 0, 0, 0, 0, 1, 0, 0 > temperature
 
typedef boost::mpl::vector_c< int, 0, 0, 0, 0, 0, 1, 0 > intensity
 
typedef boost::mpl::vector_c< int, 0, 0, 0, 0, 0, 0, 1 > amount_of_substance
 
typedef boost::mpl::vector_c< int, 0, 1, -1, 0, 0, 0, 0 > velocity
 
typedef boost::mpl::vector_c< int, 0, 1, -2, 0, 0, 0, 0 > acceleration
 
typedef boost::mpl::vector_c< int, 1, 1, -1, 0, 0, 0, 0 > momentum
 
typedef boost::mpl::vector_c< int, 1, 1, -2, 0, 0, 0, 0 > force
 

Functions

template<typename T , typename D1 , typename D2 >
quantity< T, D1 > operator+ (quantity< T, D1 > const &x, quantity< T, D2 > const &y)
 Add two quantities.
 
template<typename T , typename D1 , typename D2 >
quantity< T, D1 > operator- (quantity< T, D1 > const &x, quantity< T, D2 > const &y)
 Subtract two quantities.
 
template<typename T , typename D1 , typename D2 >
quantity< T, typename multiply_dimensions< D1, D2 >::type > operator* (quantity< T, D1 > const &x, quantity< T, D2 > const &y)
 Multiply two quantities.
 
template<typename T , typename D1 , typename D2 >
quantity< T, typename divide_dimensions< D1, D2 >::type > operator/ (quantity< T, D1 > const &x, quantity< T, D2 > const &y)
 Divide two quantities.
 

Detailed Description

Modification of algorithms from Chapter 3, Section 1.

Typedef Documentation

◆ acceleration

typedef boost::mpl::vector_c<int, 0, 1, -2, 0, 0, 0, 0> exercise_3_5::section_3_1::acceleration

Definition at line 56 of file exercise-3-5.hpp.

◆ amount_of_substance

typedef boost::mpl::vector_c<int, 0, 0, 0, 0, 0, 0, 1> exercise_3_5::section_3_1::amount_of_substance

Definition at line 52 of file exercise-3-5.hpp.

◆ charge

typedef boost::mpl::vector_c<int, 0, 0, 0, 1, 0, 0, 0> exercise_3_5::section_3_1::charge

Definition at line 49 of file exercise-3-5.hpp.

◆ force

typedef boost::mpl::vector_c<int, 1, 1, -2, 0, 0, 0, 0> exercise_3_5::section_3_1::force

Definition at line 58 of file exercise-3-5.hpp.

◆ intensity

typedef boost::mpl::vector_c<int, 0, 0, 0, 0, 0, 1, 0> exercise_3_5::section_3_1::intensity

Definition at line 51 of file exercise-3-5.hpp.

◆ length

typedef boost::mpl::vector_c<int, 0, 1, 0, 0, 0, 0, 0> exercise_3_5::section_3_1::length

Definition at line 47 of file exercise-3-5.hpp.

◆ mass

typedef boost::mpl::vector_c<int, 1, 0, 0, 0, 0, 0, 0> exercise_3_5::section_3_1::mass

Definition at line 46 of file exercise-3-5.hpp.

◆ momentum

typedef boost::mpl::vector_c<int, 1, 1, -1, 0, 0, 0, 0> exercise_3_5::section_3_1::momentum

Definition at line 57 of file exercise-3-5.hpp.

◆ scalar

typedef boost::mpl::vector_c<int, 0, 0, 0, 0, 0, 0, 0> exercise_3_5::section_3_1::scalar

Definition at line 43 of file exercise-3-5.hpp.

◆ temperature

typedef boost::mpl::vector_c<int, 0, 0, 0, 0, 1, 0, 0> exercise_3_5::section_3_1::temperature

Definition at line 50 of file exercise-3-5.hpp.

◆ time

typedef boost::mpl::vector_c<int, 0, 0, 1, 0, 0, 0, 0> exercise_3_5::section_3_1::time

Definition at line 48 of file exercise-3-5.hpp.

◆ velocity

typedef boost::mpl::vector_c<int, 0, 1, -1, 0, 0, 0, 0> exercise_3_5::section_3_1::velocity

Definition at line 55 of file exercise-3-5.hpp.

Function Documentation

◆ operator*()

template<typename T , typename D1 , typename D2 >
quantity< T, typename multiply_dimensions< D1, D2 >::type > exercise_3_5::section_3_1::operator* ( quantity< T, D1 > const &  x,
quantity< T, D2 > const &  y 
)

Multiply two quantities.

Template Parameters
TThe container type for the quantity's value.
D1The first quantity's dimensions.
D2The second quantity's dimensions.
Parameters
[in]xThe first quantity to multiply.
[in]yThe second quantity to multiply.
Returns
A new quantity whose value is a product of the inputs, and whose dimensions are similarly a product of the inputs' dimensions.

Definition at line 197 of file exercise-3-5.hpp.

◆ operator+()

template<typename T , typename D1 , typename D2 >
quantity< T, D1 > exercise_3_5::section_3_1::operator+ ( quantity< T, D1 > const &  x,
quantity< T, D2 > const &  y 
)

Add two quantities.

Template Parameters
TThe container type for the quantity's value.
D1The quantity's resulting dimensions.
D2Dimensions for an input quantity that are compatible with the output dimensions.
Parameters
[in]xThe first quantity to add.
[in]yThe second quantity to add.
Returns
A new quantity with the same dimensions as the first input quantity whose value is the sum of both input quantities.

Definition at line 127 of file exercise-3-5.hpp.

◆ operator-()

template<typename T , typename D1 , typename D2 >
quantity< T, D1 > exercise_3_5::section_3_1::operator- ( quantity< T, D1 > const &  x,
quantity< T, D2 > const &  y 
)

Subtract two quantities.

Template Parameters
TThe container type for the quantity's value.
D1The quantity's resulting dimensions.
D2Dimensions for an input quantity that are compatible with the output dimensions.
Parameters
[in]xThe first quantity to subtract.
[in]yThe second quantity to subtract.
Returns
A new quantity with the same dimensions as the first input quantity whose value is the difference of both input quantities.

Definition at line 148 of file exercise-3-5.hpp.

◆ operator/()

template<typename T , typename D1 , typename D2 >
quantity< T, typename divide_dimensions< D1, D2 >::type > exercise_3_5::section_3_1::operator/ ( quantity< T, D1 > const &  x,
quantity< T, D2 > const &  y 
)

Divide two quantities.

Template Parameters
TThe container type for the quantity's value.
D1The first quantity's dimensions.
D2The second quantity's dimensions.
Parameters
[in]xThe first quantity to divide.
[in]yThe second quantity to divide.
Returns
A new quantity whose value is a quotient of the inputs, and whose dimensions are similarly a quotient of the inputs' dimensions.

Definition at line 218 of file exercise-3-5.hpp.