From 6a94ebba82adf136f93eb914d95e7c9c95d373eb Mon Sep 17 00:00:00 2001 From: Clonkk Date: Mon, 12 Apr 2021 11:26:59 +0200 Subject: [PATCH 1/3] add constructors pragma to init proc --- cppstl/std_complex.nim | 2 +- cppstl/std_smartptrs.nim | 2 ++ cppstl/std_string.nim | 16 ++++++++-------- cppstl/std_vector.nim | 10 +++++----- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/cppstl/std_complex.nim b/cppstl/std_complex.nim index 2ebc7a4..f947099 100644 --- a/cppstl/std_complex.nim +++ b/cppstl/std_complex.nim @@ -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()".} diff --git a/cppstl/std_smartptrs.nim b/cppstl/std_smartptrs.nim index 4ac57ff..2e03605 100644 --- a/cppstl/std_smartptrs.nim +++ b/cppstl/std_smartptrs.nim @@ -1,5 +1,7 @@ import std/macros +when not defined(cpp): + {.error: "C++ backend required to use STL wrapper".} # std::shared_ptr # ----------------------------------------------------------------------- {.push header: "".} diff --git a/cppstl/std_string.nim b/cppstl/std_string.nim index 0c06b5d..89c4cd4 100644 --- a/cppstl/std_string.nim +++ b/cppstl/std_string.nim @@ -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".} diff --git a/cppstl/std_vector.nim b/cppstl/std_vector.nim index 07d898f..efdd1bf 100644 --- a/cppstl/std_vector.nim +++ b/cppstl/std_vector.nim @@ -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".} From 2f6ff912028ca3fe7f93e39a842fdecf67e0af3f Mon Sep 17 00:00:00 2001 From: Clonkk Date: Mon, 12 Apr 2021 11:29:52 +0200 Subject: [PATCH 2/3] fix readme --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2ae0b09..3310cab 100644 --- a/README.md +++ b/README.md @@ -30,9 +30,10 @@ 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 From 8ca8703a2be9d0fb70aa7782ce53c2a3ea47f09b Mon Sep 17 00:00:00 2001 From: Clonkk Date: Mon, 12 Apr 2021 11:30:32 +0200 Subject: [PATCH 3/3] readme syntax --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3310cab..ee61b55 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ requires "cppstl" ## 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