No description
Find a file
2024-09-16 13:45:02 +02:00
.github/workflows fix depcreation gh actions versions 2024-09-16 13:44:06 +02:00
cppstl Merge branch 'fix-destructor' into fix-nim-2.0.4 2024-09-16 10:53:09 +02:00
docs fix CI; add separate CI to check docs; update gitignore 2024-09-16 11:44:21 +02:00
tests fix CI; add separate CI to check docs; update gitignore 2024-09-16 11:44:21 +02:00
.gitattributes Add .gitattributes 2021-04-02 15:26:35 +02:00
.gitignore fix CI; add separate CI to check docs; update gitignore 2024-09-16 11:44:21 +02:00
config.nims fix CI; add separate CI to check docs; update gitignore 2024-09-16 11:44:21 +02:00
cppstl.nim remove redundant runnableExample 2024-09-16 11:36:22 +02:00
cppstl.nimble bump nimble 2024-09-16 11:21:19 +02:00
LICENSE.txt complete std::complex tests 2021-04-08 10:12:16 +02:00
README.md update badge 2024-09-16 13:45:02 +02:00

Nim bindings for the C++ STL

workflow workflow

Introduction

This library is a Nim wrapper for C++ Standard Template Library (STL) class. This library is obviously only compatible with the C++ backend

I recommand using this bindings only in two cases:

  • When wrapping a C++ library (But make sure to offer a Nim idomatic API that does not expose the STL to the user if possible).
  • In some performance critical code where the cost of converting Nim types to c++ types is problematic (like embeded devices).

Installation

nimble install cppstl

Add the following lines to your .nimble:

backend = "cpp"
requires "cppstl"

Limitations

cppstl currently wraps :

  • std::string

  • std::basic_string

  • std::vector

  • std::complex

  • std::pair

  • Smart pointers are partially supported:

    • std::unique_ptr
    • std::shared_ptr

Avoid using wrapped STL objects in top-level Nim scope.

Most of the times it works on Nim 1.x but leads to both compile-time and runtime errors on 2.x. So instantiate them in subroutines only to ensure portability between 1.x and 2.x.

I.e this usecase is not recommended:

when isMainModule:
  var vec = initCppVector[int]()
  vec.pushBack(20)

Use this one instead:

when isMainModule:
  proc foo = 
    var vec = initCppVector[int]()
    vec.pushBack(20)
  foo()

Contributions

All contributions are welcome!

If there is a missing function or class, that you need, don't be shy to open an issue or a PR.

Running Tests

nimble test

or

testament p "tests/t*.nim"

Usage

The documentation is here : https://clonkk.github.io/nim-cppstl/cppstl.html

You can find more use-case in the tests folder.

License

This code is licensed under MIT license (see LICENSE.txt for details)