Types
CppVector[T] {.importcpp: "std::vector".} = object
CppVectorConstIterator[T] {.importcpp: "std::vector<\'0>::const_iterator".} = CppConstIterator[ T]
CppVectorIterator[T] {.importcpp: "std::vector<\'0>::iterator".} = CppIterator[T]
Procs
proc `!=`[T](a: CppVector[T]; b: CppVector[T]): bool {.importcpp: "(# != #)", header: "<vector>", ...raises: [], tags: [], forbids: [].}
-
Return true if the contents of lhs and rhs are not equal, that is, either they do not have the same number of elements, or one of the elements in lhs does not compare equal with the element in rhs at the same position.
https://en.cppreference.com/w/cpp/container/CppVector/operator_cmp
Example:
let v1 = @[1, 2, 3].toCppVector() var v2 = v1 v3 = v1 v2.add(4) doAssert v2 != v1 v3[0] = 100 doAssert v3 != v1
proc `<`[T](a: CppVector[T]; b: CppVector[T]): bool {.importcpp: "(# < #)", header: "<vector>", ...raises: [], tags: [], forbids: [].}
-
Return true if a is lexicographically less than b.
https://en.cppreference.com/w/cpp/container/CppVector/operator_cmp
Example:
let v1 = @[1, 2, 3].toCppVector() var v2 = v1 doAssert not (v1 < v2) v2.add(4) doAssert v1 < v2 v2[2] = 0 doAssert v2 < v1
proc `<=`[T](a: CppVector[T]; b: CppVector[T]): bool {.importcpp: "(# <= #)", header: "<vector>", ...raises: [], tags: [], forbids: [].}
-
Return true if a is lexicographically less than or equal to b.
https://en.cppreference.com/w/cpp/container/CppVector/operator_cmp
Example:
let v1 = @[1, 2, 3].toCppVector() var v2 = v1 doAssert v1 <= v2 v2.add(4) doAssert v1 <= v2 v2[2] = 0 doAssert v2 <= v1
proc `==`[T](a: CppVector[T]; b: CppVector[T]): bool {.importcpp: "(# == #)", header: "<vector>", ...raises: [], tags: [], forbids: [].}
-
Return true if the contents of lhs and rhs are equal, that is, they have the same number of elements and each element in lhs compares equal with the element in rhs at the same position.
https://en.cppreference.com/w/cpp/container/CppVector/operator_cmp
Example:
let v1 = @[1, 2, 3].toCppVector() v2 = v1 doAssert v1 == v2
proc `>`[T](a: CppVector[T]; b: CppVector[T]): bool {.importcpp: "(# > #)", header: "<vector>", ...raises: [], tags: [], forbids: [].}
-
Return true if a is lexicographically greater than b.
https://en.cppreference.com/w/cpp/container/CppVector/operator_cmp
Example:
let v1 = @[1, 2, 3].toCppVector() var v2 = v1 doAssert not (v2 > v1) v2.add(4) doAssert v2 > v1 v2[2] = 0 doAssert v1 > v2
proc `>=`[T](a: CppVector[T]; b: CppVector[T]): bool {.importcpp: "(# >= #)", header: "<vector>", ...raises: [], tags: [], forbids: [].}
-
Return true if a is lexicographically greater than or equal to b.
https://en.cppreference.com/w/cpp/container/CppVector/operator_cmp
Example:
let v1 = @[1, 2, 3].toCppVector() var v2 = v1 doAssert v2 >= v1 v2.add(4) doAssert v2 >= v1 v2[2] = 0 doAssert v1 >= v2
proc add[T](v: var CppVector[T]; elem: T) {.inline.}
-
Alias for pushBack proc.
Example:
var v = initCppVector[int]() doAssert v.len() == 0 v.add(100) v.add(200) doAssert v.len() == 2
proc assign[T](first: CppVectorIterator[T]; last: CppVectorIterator[T]) {. importcpp: "assign", header: "<vector>", ...raises: [], tags: [], forbids: [].}
proc assign[T](n: csize_t; val: T) {.importcpp: "assign", header: "<vector>", ...raises: [], tags: [], forbids: [].}
proc assign[T](v: var CppVector[T]; num: csize_t; val: T) {.importcpp: "assign", header: "<vector>", ...raises: [], tags: [], forbids: [].}
-
Return a CppVector with num elements assigned to the specified value val.
https://en.cppreference.com/w/cpp/container/CppVector/assign
Example:
var v: CppVector[float] v.assign(5, 1.0) doAssert v.toSeq() == @[1.0, 1.0, 1.0, 1.0, 1.0] v.assign(2, 2.3) doAssert v.toSeq() == @[2.3, 2.3]
proc back[T](v: CppVector[T]): T {.importcpp: "back", header: "<vector>", ...raises: [], tags: [], forbids: [].}
proc back[T](v: var CppVector[T]): var T {.importcpp: "back", header: "<vector>", ...raises: [], tags: [], forbids: [].}
-
Return the reference to the last element of the CppVector.
This has an alias proc last.
https://www.cplusplus.com/reference/CppVector/CppVector/back/
Example:
var v = initCppVector[int]() v.add(100) v.add(200) doAssert v.back() == 200 v.back() = 300 doAssert v.back() == 300
proc begin[T](v: CppVector[T]): CppVectorIterator[T] {.importcpp: "begin", header: "<vector>", ...raises: [], tags: [], forbids: [].}
-
Return a mutable C++ iterator pointing to the beginning position of the CppVector.
https://www.cplusplus.com/reference/CppVector/CppVector/begin/
Example:
var v = @[1, 2, 3].toCppVector() discard v.insert(v.begin(), 100) doAssert v.toSeq() == @[100, 1, 2, 3]
proc cBegin[T](v: CppVector[T]): CppVectorConstIterator[T] {. importcpp: "cbegin", header: "<vector>", ...raises: [], tags: [], forbids: [].}
-
Return an immutable C++ iterator pointing to the beginning position of the CppVector.
https://www.cplusplus.com/reference/CppVector/CppVector/begin/
Example:
var v = @[1, 2, 3].toCppVector() discard v.insert(v.cBegin(), 100) doAssert v.toSeq() == @[100, 1, 2, 3]
proc cEnd[T](v: CppVector[T]): CppVectorConstIterator[T] {.importcpp: "cend", header: "<vector>", ...raises: [], tags: [], forbids: [].}
-
Return an immutable C++ iterator pointing to after the end position of the CppVector.
https://www.cplusplus.com/reference/CppVector/CppVector/end/
Example:
var v = @[1, 2, 3].toCppVector() discard v.insert(v.cEnd(), 100) doAssert v.toSeq() == @[1, 2, 3, 100]
proc crBegin[T](x: CppVector[T]): CppVectorConstIterator[T] {. importcpp: "crbegin", header: "<vector>", ...raises: [], tags: [], forbids: [].}
proc crEnd[T](x: CppVector[T]): CppVectorConstIterator[T] {.importcpp: "crend", header: "<vector>", ...raises: [], tags: [], forbids: [].}
proc empty(v: CppVector): bool {.importcpp: "empty", header: "<vector>", ...raises: [], tags: [], forbids: [].}
-
Check if the CppVector is empty i.e. has zero elements.
https://en.cppreference.com/w/cpp/container/CppVector/empty
Example:
var v = initCppVector[int]() doAssert v.empty() v.add(100) doAssert not v.empty()
proc `end`[T](v: CppVector[T]): CppVectorIterator[T] {.importcpp: "end", header: "<vector>", ...raises: [], tags: [], forbids: [].}
-
Return a mutable C++ iterator pointing to after the end position of the CppVector.
https://www.cplusplus.com/reference/CppVector/CppVector/end/
Example:
var v = @[1, 2, 3].toCppVector() discard v.insert(v.`end`(), 100) doAssert v.toSeq() == @[1, 2, 3, 100]
proc erase[T](self: var CppVector[T]; first, last: CppVectorConstIterator[T]): CppVectorIterator[ T] {.importcpp: "erase", header: "<vector>", ...raises: [], tags: [], forbids: [].}
proc erase[T](self: var CppVector[T]; position: CppVectorConstIterator[T]): CppVectorIterator[ T] {.importcpp: "erase", header: "<vector>", ...raises: [], tags: [], forbids: [].}
proc first[T](v: CppVector[T]): T {.inline.}
- Alias for front proc.
proc first[T](v: var CppVector[T]): var T {.inline.}
-
Alias for front proc.
Example:
var v = initCppVector[int]() v.add(100) v.add(200) doAssert v.first() == 100 v.first() = 300 doAssert v.first() == 300
proc front[T](v: CppVector[T]): T {.importcpp: "front", header: "<vector>", ...raises: [], tags: [], forbids: [].}
proc front[T](v: var CppVector[T]): var T {.importcpp: "front", header: "<vector>", ...raises: [], tags: [], forbids: [].}
-
Return the reference to the first element of the CppVector.
This has an alias proc first.
https://en.cppreference.com/w/cpp/container/CppVector/front
Example:
var v = initCppVector[int]() v.add(100) v.add(200) doAssert v.front() == 100 v.front() = 300 doAssert v.front() == 300
proc initCppVector[T](): CppVector[T] {.constructor, importcpp: "std::vector<\'*0>(@)", header: "<vector>".}
proc initCppVector[T](first, last: CppVectorConstIterator[T]): CppVector[T] {. constructor, importcpp: "std::vector<\'*0>(@)", header: "<vector>".}
proc initCppVector[T](n: csize_t): CppVector[T] {.constructor, importcpp: "std::vector<\'*0>(@)", header: "<vector>".}
proc initCppVector[T](n: csize_t; val: T): CppVector[T] {.constructor, importcpp: "std::vector<\'*0>(@)", header: "<vector>".}
proc initCppVector[T](x: CppVector[T]): CppVector[T] {.constructor, importcpp: "std::vector<\'*0>(@)", header: "<vector>".}
proc insert[T](v: var CppVector[T]; position, first, last: CppVectorConstIterator[T]): CppVectorIterator[ T] {.importcpp: "insert", header: "<vector>", ...raises: [], tags: [], forbids: [].}
-
Insert elements from range first ..< last before the specified position.
Example:
let v1 = @['a', 'b'].toCppVector() var v2: CppVector[char] discard v2.insert(v2.cBegin(), v1.cBegin(), v1.cEnd()) doAssert v2.toSeq() == @['a', 'b']
proc insert[T](v: var CppVector[T]; position: CppVectorConstIterator[T]; count: csize_t; val: T): CppVectorIterator[T] {. importcpp: "insert", header: "<vector>", ...raises: [], tags: [], forbids: [].}
-
Insert count copies of element before the specified position.
Example:
var v = @['a', 'b'].toCppVector() discard v.insert(v.cBegin(), 3, 'c') doAssert v.toSeq() == @['c', 'c', 'c', 'a', 'b']
proc insert[T](v: var CppVector[T]; position: CppVectorConstIterator[T]; val: T): CppVectorIterator[ T] {.importcpp: "insert", header: "<vector>", ...raises: [], tags: [], forbids: [].}
-
Insert an element before the specified position.
Example:
var v = @['a', 'b'].toCppVector() discard v.insert(v.cBegin(), 'c') doAssert v.toSeq() == @['c', 'a', 'b']
proc popBack[T](v: var CppVector[T]) {.importcpp: "pop_back", header: "<vector>", ...raises: [], tags: [], forbids: [].}
-
Remove the last element of the CppVector. This proc does not return anything.
https://www.cplusplus.com/reference/CppVector/CppVector/pop_back/
Example:
var v = initCppVector[int]() doAssert v.len() == 0 v.add(100) doAssert v.len() == 1 v.popBack() doAssert v.len() == 0
proc pushBack[T](v: var CppVector[T]; elem: T) {.importcpp: "push_back", header: "<vector>", ...raises: [], tags: [], forbids: [].}
-
Append a new element to the end of the CppVector.
This has an alias proc add.
https://en.cppreference.com/w/cpp/container/CppVector/push_back
Example:
var v = initCppVector[int]() doAssert v.len() == 0 v.pushBack(100) v.pushBack(200) doAssert v.len() == 2
proc rBegin[T](x: CppVector[T]): CppVectorIterator[T] {.importcpp: "rbegin", header: "<vector>", ...raises: [], tags: [], forbids: [].}
proc rEnd[T](x: CppVector[T]): CppVectorIterator[T] {.importcpp: "rend", header: "<vector>", ...raises: [], tags: [], forbids: [].}
proc shrinkToFit[T](self: var CppVector[T]) {.importcpp: "shrink_to_fit", header: "<vector>", ...raises: [], tags: [], forbids: [].}
proc size(v: CppVector): csize_t {.importcpp: "size", header: "<vector>", ...raises: [], tags: [], forbids: [].}
-
Return the number of elements in the CppVector.
This has an alias proc len.
https://en.cppreference.com/w/cpp/container/CppVector/size
Example:
var v = initCppVector[int]() doAssert v.size() == 0 v.add(100) v.add(200) doAssert v.len() == 2 doAssert v.size() == 2
proc swap[T](v1, v2: var CppVector[T]) {.importcpp: "swap", header: "<vector>", ...raises: [], tags: [], forbids: [].}
-
Swap the contents of vectors v1 and v2.
https://en.cppreference.com/w/cpp/container/CppVector/swap
Example:
var v1 = @[1, 2, 3].toCppVector() v2 = @[7, 8, 9].toCppVector() v1.swap(v2) doAssert v1.toSeq() == @[7, 8, 9] doAssert v2.toSeq() == @[1, 2, 3]
proc toCppVector[T](s: openArray[T]): CppVector[T]
-
Convert an array/sequence to a CppVector.
Example:
let s = @[1, 2, 3] a = [1, 2, 3] doAssert s.toCppVector().toSeq() == s doAssert a.toCppVector().toSeq() == s
Converters
converter CppVectorIteratorToCppVectorConstIterator[T](x: CppVectorIterator[T]): CppVectorConstIterator[ T] {.importcpp: "#", ...raises: [], tags: [], forbids: [].}
- Implicitly convert mutable C++ iterator to immutable C++ iterator.
Templates
template constIterator[T](_: typedesc[CppVector[T]]): typedesc[ CppVectorConstIterator[T]]
template `iterator`[T](_: typedesc[CppVector[T]]): typedesc[CppVectorIterator[T]]
Exports
-
inc, ==, inc, ==, +, -, CppConstIterator, CppIterator, [], [], OutOfRangeException