Giter VIP home page Giter VIP logo

nim-cppstl's Introduction

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

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)

nim-cppstl's People

Contributors

bigepsilon avatar clonkk avatar kaushalmodi avatar mantielero avatar nouredineh avatar timotheecour avatar vindaar avatar z------------- avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nim-cppstl's Issues

Error: static assertion failed

Hi there, I'm getting multiples errors while compiling a dll

my ffi.nim files only contains an import:

import cppstl/std_string

compile:

nim c --cpu:i386 -d:release --app:lib --nomain ffi.nim

D:\nim\lib/nimbase.h:550:30: error: static assertion failed
550 | NIM_STATIC_ASSERT(sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8, "");
D:\nim\lib/nimbase.h:278:50: note: in definition of macro 'NIM_STATIC_ASSERT'
278 | #define NIM_STATIC_ASSERT(x, msg) static_assert((x), msg)
|

Nim Compiler Version 1.6.6 [Windows: i386]

doesn't work with destructors

continuing of kaushalmodi/std_vector#4 since the other repo was merged here

example

when defined case2:
  import cppstl/std_vector
  type Foo = object
    x: int
  proc `=destroy`*(a: var Foo) {.inline.} =
    echo ("in destroy", a.x)
  proc main =
    var v1 = initCppVector[Foo]()
    echo v1
    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"
  main()

gives:

[]
ok0
("in destroy", 10)
("in destroy", 11)
("in destroy", 12)
[(x: 10), (x: 11), (x: 12)]
ok1
("in destroy", 10)
("in destroy", 11)
("in destroy", 12)
[(x: 10), (x: 11), (x: 12)]
ok2

(with both gc:arc|refc)

expected result

same as for here, with seq instead of vector:

when defined case3:
  import cppstl/std_vector
  type Foo = object
    x: int
  proc `=destroy`*(a: var Foo) {.inline.} =
    echo ("in destroy", a.x)
  proc main =
    var v: seq[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"
  main()

with --gc:arc and --gc:refc, this gives:

ok0
@[(x: 10), (x: 11), (x: 12)]
ok1
@[(x: 10), (x: 11), (x: 12)]
ok2
("in destroy", 10)
("in destroy", 11)
("in destroy", 12)

as it should

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.