This file contains implementation of Vector class.
More...
#include <cstddef>
#include <initializer_list>
#include <iostream>
#include <iterator>
#include <memory>
Go to the source code of this file.
|
| template<typename T> |
| void | dsa::swap (Vector< T > &vector1, Vector< T > &vector2) noexcept |
| | Exchanges content of two Vector containers.
|
| template<typename T> |
| auto | dsa::operator<< (std::ostream &out, const Vector< T > &vector) -> std::ostream & |
| | Overloads operator to print all elements of Vector.
|
| template<typename T> |
| auto | dsa::operator== (const Vector< T > &vector1, const Vector< T > &vector2) -> bool |
| | The relational operator compares two Vector objects.
|
| template<typename T> |
| constexpr auto | dsa::operator<=> (const Vector< T > &vector1, const Vector< T > &vector2) |
| | The relational operator compares two Vector objects.
|
This file contains implementation of Vector class.
- Author
- Michal Zygmunt
- Copyright
- Copyright (c) 2025 Michal Zygmunt This project is distributed under the MIT License. See accompanying LICENSE.txt file or obtain copy at https://opensource.org/license/mit
Definition in file vector.h.
◆ operator<<()
template<typename T>
| auto dsa::operator<< |
( |
std::ostream & | out, |
|
|
const Vector< T > & | vector ) -> std::ostream&
|
Overloads operator to print all elements of Vector.
- Template Parameters
-
| T | data type stored in container |
- Parameters
-
| [in,out] | out | reference to output stream |
| [in] | vector | Vector to print |
- Returns
- std::ostream&
Definition at line 1438 of file vector.h.
1439 {
1440 for (
size_t i = 0; i < vector.
size(); i++)
1441 {
1442 out << vector[i] << ' ';
1443 }
1444
1445 return out;
1446 }
constexpr auto size() const noexcept -> size_type
Returns number of elements in container.
◆ operator<=>()
template<typename T>
| auto dsa::operator<=> |
( |
const Vector< T > & | vector1, |
|
|
const Vector< T > & | vector2 ) |
|
constexpr |
The relational operator compares two Vector objects.
- Parameters
-
| [in] | vector1 | input container |
| [in] | vector2 | input container |
- Return values
-
| -1 | if the content of vector1 is lexicographically lesser than the content of vector2 |
| 0 | if the content of vector1 and vector2 is equal |
| +1 | if the content of vector1 is lexicographically greater than the content of vector2 |
Definition at line 1493 of file vector.h.
1494 {
1495 auto vector1_iter = vector1.
cbegin();
1496 auto vector2_iter = vector2.
cbegin();
1497
1498 while (vector1_iter != vector1.
cend() && vector2_iter != vector2.
cend())
1499 {
1500 if (*vector1_iter < *vector2_iter)
1501 {
1502 return std::strong_ordering::less;
1503 }
1504 if (*vector1_iter > *vector2_iter)
1505 {
1506 return std::strong_ordering::greater;
1507 }
1508
1509 vector1_iter++;
1510 vector2_iter++;
1511 }
1512
1513 if (vector1.
size() < vector2.
size())
1514 {
1515 return std::strong_ordering::less;
1516 }
1517 if (vector1.
size() > vector2.
size())
1518 {
1519 return std::strong_ordering::greater;
1520 }
1521
1522 return std::strong_ordering::equivalent;
1523 }
constexpr auto cbegin() const noexcept -> const_iterator
Returns const_iterator to first element.
constexpr auto cend() const noexcept -> const_iterator
Returns const_iterator past last element of underlaying data structure.
◆ operator==()
template<typename T>
| auto dsa::operator== |
( |
const Vector< T > & | vector1, |
|
|
const Vector< T > & | vector2 ) -> bool
|
The relational operator compares two Vector objects.
- Template Parameters
-
| T | type of data stored in container |
- Parameters
-
| [in] | vector1 | input container |
| [in] | vector2 | input container |
- Return values
-
| true | if containers are equal |
| false | if containers are not equal |
Definition at line 1458 of file vector.h.
1459 {
1460 if (vector1.
size() != vector2.
size())
1461 {
1462 return false;
1463 }
1464
1465 auto vector1_iter = vector1.
cbegin();
1466 auto vector2_iter = vector2.
cbegin();
1467
1468
1469 while (vector1_iter != vector1.
cend())
1470 {
1471 if (*vector1_iter != *vector2_iter)
1472 {
1473 return false;
1474 }
1475
1476 vector1_iter++;
1477 vector2_iter++;
1478 }
1479
1480 return true;
1481 }
◆ swap()
template<typename T>
| void dsa::swap |
( |
Vector< T > & | vector1, |
|
|
Vector< T > & | vector2 ) |
|
noexcept |
Exchanges content of two Vector containers.
- Template Parameters
-
| T | data type stored in containers |
- Parameters
-
| [in] | vector1 | container to swap content |
| [in] | vector2 | container to swap content |
Definition at line 1424 of file vector.h.
1425 {
1426 vector1.
swap(vector2);
1427 }
constexpr void swap(Vector< T > &other) noexcept
Exchanges content of current container with other container.