Skip to content

Commit

Permalink
Merge pull request #10 from Clonkk/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Clonkk authored Apr 12, 2021
2 parents f07f5aa + 8ca8703 commit 49399f7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ requires "cppstl"
* ``std::string``
* ``std::std_vector``
* ``std::complex``

* Smart pointers are partially supported:
* ``std::unique_ptr``
* ``std::shared_ptr``
* ``std::unique_ptr``
* ``std::shared_ptr``

## Contributions

All contributions are welcome !
If there is a missing function or class, that you need, don't be shy and open an issue (or a even better a PR ;) ).
If there is a missing function or class, that you need, don't be shy to open an issue or a PR.

## Usage

Expand Down
2 changes: 1 addition & 1 deletion cppstl/std_complex.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
type
CppComplex*[T: SomeFloat] {.importcpp: "std::complex".} = object

func initCppComplex*[T: SomeFloat](re, im: T): CppComplex[T] {.importcpp: "std::complex<'*0>(@)".}
func initCppComplex*[T: SomeFloat](re, im: T): CppComplex[T] {.constructor, importcpp: "std::complex<'*0>(@)".}
func polar*[T: SomeFloat](r, theta: T): CppComplex[T] {.importcpp: "std::polar<'*0>(@)".}

func real*[T: SomeFloat](self: CppComplex[T]): T {.importcpp: "#.real()".}
Expand Down
2 changes: 2 additions & 0 deletions cppstl/std_smartptrs.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import std/macros

when not defined(cpp):
{.error: "C++ backend required to use STL wrapper".}
# std::shared_ptr<T>
# -----------------------------------------------------------------------
{.push header: "<memory>".}
Expand Down
16 changes: 8 additions & 8 deletions cppstl/std_string.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ type
CppStrIterator* {.importcpp: "std::string::iterator".} = object
CppStrConstIterator* {.importcpp: "std::string::const_iterator".} = object

# std_npos is declared as the highest possible value of csize_t
# std::string::npos is declared as the highest possible value of csize_t
# In C++ it is -1 due how overflow works
const std_npos*: csize_t = high(typedesc[csize_t])

#Constructor
proc initCppString*(): CppString {.importcpp: "std::string()".}
proc initCppString*(str: CppString): CppString {.importcpp: "std::string(@)".}
proc initCppString*(str: CppString, pos: csize_t): CppString {.importcpp: "std::string(@)".}
proc initCppString*(str: CppString, pos, len: csize_t): CppString {.importcpp: "std::string(@)".}
proc initCppString*(s: cstring): CppString {.importcpp: "std::string(@)".}
proc initCppString*(s: cstring, n: csize_t): CppString {.importcpp: "std::string(@)".}
proc initCppString*(first, last: CppStrConstIterator): CppString {.importcpp: "std::string(@)".}
proc initCppString*(): CppString {.constructor, importcpp: "std::string()".}
proc initCppString*(str: CppString): CppString {.constructor, importcpp: "std::string(@)".}
proc initCppString*(str: CppString, pos: csize_t): CppString {.constructor, importcpp: "std::string(@)".}
proc initCppString*(str: CppString, pos, len: csize_t): CppString {.constructor, importcpp: "std::string(@)".}
proc initCppString*(s: cstring): CppString {.constructor, importcpp: "std::string(@)".}
proc initCppString*(s: cstring, n: csize_t): CppString {.constructor, importcpp: "std::string(@)".}
proc initCppString*(first, last: CppStrConstIterator): CppString {.constructor, importcpp: "std::string(@)".}

# Iterators
proc begin*(x: CppString): CppStrIterator {.importcpp: "begin".}
Expand Down
10 changes: 5 additions & 5 deletions cppstl/std_vector.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ type
CppVectorConstIterator*[T] {.importcpp: "std::vector<'0>::const_iterator".} = object

# Constructors
proc initCppVector*[T](): CppVector[T] {.importcpp: "std::vector<'*0>(@)".}
proc initCppVector*[T](n: csize_t): CppVector[T] {.importcpp: "std::vector<'*0>(@)".}
proc initCppVector*[T](n: csize_t, val: T): CppVector[T] {.importcpp: "std::vector<'*0>(@)".}
proc initCppVector*[T](x: CppVector[T]): CppVector[T] {.importcpp: "std::vector<'*0>(@)".}
proc initCppVector*[T](first, last: CppVectorConstIterator[T]): CppVector[T] {.importcpp: "std::vector<'*0>(@)".}
proc initCppVector*[T](): CppVector[T] {.constructor, importcpp: "std::vector<'*0>(@)".}
proc initCppVector*[T](n: csize_t): CppVector[T] {.constructor, importcpp: "std::vector<'*0>(@)".}
proc initCppVector*[T](n: csize_t, val: T): CppVector[T] {.constructor, importcpp: "std::vector<'*0>(@)".}
proc initCppVector*[T](x: CppVector[T]): CppVector[T] {.constructor, importcpp: "std::vector<'*0>(@)".}
proc initCppVector*[T](first, last: CppVectorConstIterator[T]): CppVector[T] {.constructor, importcpp: "std::vector<'*0>(@)".}

# Iterators
proc begin*[T](x: CppVector[T]): CppVectorIterator[T] {.importcpp: "begin".}
Expand Down

0 comments on commit 49399f7

Please sign in to comment.