Skip to content

Commit

Permalink
Merge pull request #19 from Clonkk/destroy_bug_15
Browse files Browse the repository at this point in the history
Destroy bug 15
  • Loading branch information
Clonkk authored Jun 28, 2021
2 parents ad46fa5 + c3ba630 commit 8a99cb9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cppstl/std_complex.nim
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ func conj*[T: SomeFloat](self: CppComplex[T]): CppComplex[T] {.importcpp: "std::
{.pop.}

import complex
proc toComplex*[T](c: CppComplex[T]) : Complex[T] =
proc toComplex*[T](c: CppComplex[T]): Complex[T] =
result.re = c.real()
result.im = c.imag()

proc toCppComplex*[T](c: Complex[T]) : CppComplex[T] =
proc toCppComplex*[T](c: Complex[T]): CppComplex[T] =
result = initCppComplex(c.re, c.im)

proc `$`*[T](c: CppComplex[T]): string =
Expand Down
4 changes: 2 additions & 2 deletions cppstl/std_string.nim
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ proc last*(v: CppString): cchar {.inline.} =
v.back()

# Nim Iterators
iterator items*(v: CppString): cchar=
iterator items*(v: CppString): cchar =
## Iterate over all the elements in CppString `v`.
for idx in 0.csize_t ..< v.len():
yield v[idx]
Expand All @@ -297,7 +297,7 @@ iterator pairs*(v: CppString): (csize_t, cchar) =
for idx in 0.csize_t ..< v.len():
yield (idx, v[idx])

iterator mitems*(v: var CppString): var cchar=
iterator mitems*(v: var CppString): var cchar =
## Iterate over all the elements in CppString `v`.
for idx in 0.csize_t ..< v.len():
yield v[idx]
Expand Down
2 changes: 1 addition & 1 deletion cppstl/std_vector.nim
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ proc last*[T](v: CppVector[T]): T {.inline.} =

# Nim Iterators

iterator items*[T](v: CppVector[T]): T=
iterator items*[T](v: CppVector[T]): T =
## Iterate over all the elements in CppVector `v`.
runnableExamples:
var
Expand Down
28 changes: 28 additions & 0 deletions tests/destroy_bug_15.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import cppstl/std_vector

type Foo = object
x: int

proc `=destroy`*(a: var Foo) {.inline.} =
echo ("in destroy", a.x)

proc main =
var v = initCppVector[Foo]()

v.add Foo(x: 10)
v.add Foo(x: 11)
v.add Foo(x: 12)

echo "ok0"
echo v

echo "ok1"
echo v

echo "ok2"

# Clear should call object destructor
v.clear()
echo "ok3"

main()

0 comments on commit 8a99cb9

Please sign in to comment.