MyArray osztály
class OutOfRange: public std::exception
{};
template
class MyArray
{
public:
MyArray()
{}
MyArray(const std::initializer_list& init)
//initializer list constructor: MyArray<5, int> mya = {0, 1, 2, 3};
{
for(int i(0); i
concept_map Range> //no ' ' in >>
{
typedef T* range_iterator::type;
typedef T value_type;
//begin and end are correct
};
/*
* Describing how MyArray fulfills Container concept's restrictions,
* so it can be used in standard algorithms efficiently
*/
template
concept_map Container>
{
typedef T value_type;
typedef T* iterator;
typedef const T* const_iterator;
typedef T& reference;
typedef const T& const_reference;
//... more types
//begin, end correct
bool empty() //array is always full -> never empty
{
return false;
}
unsigned size() //its size is always its maximum
{
return size;
}
unsigned max_size()
{
return size;
}
}
Forrás
Mátrix osztály
/*
* Defining a concept so we can work with T as numbers
* We reuse the LessThanComparable standard concept to reduce complexity
*/
auto concept Number
{
T operator+(const T&, const T&);
T& operator+=(T&, const T&);
//...
};
/*
* Type param fulfills Number concept
*/
template
class Matrix
{
public:
Matrix(unsigned row, unsigned col): row(row), col(col)
{
Create();
}
/*
* Rvalue constructor: efficient copying of temporaly objects
*/
Matrix(Matrix&& oth): row(oth.Row()), col(oth.Col())
{
Create();
T** tmp = matr;
matr = oth.matr;
oth.matr = tmp;
}
~Matrix()
{
for(int i(0); i
void Apply(Func func)
{
for(int i(0); i
Forrás