Using C++ STL library
Is now in the development stage.

Using STL in C++ Smart-Contracts

Limitations

As x64-vm is running in an isolated environment it does not support system calls, so all functions from libc and from STL that use them would not compile.
The most common examples are:

CMake project setup and examples

Example of x64 contracts with STL support are available in tests/stl_tests/test_contracts directory. CMake files for gcc version 7 and clang 10 STL support are located in scripts directory. For gcc version 8 and version 9 STL scripts should be modified accordingly.

Compiling with AppleClang

AppleClang requires to define custom allocator in collections, so you have to instantiate string, vector and map with explicit custom allocator:
1
// `stl_allocator` is defined in x86-64/contracts/libstd/stl_allocator.hpp
2
3
// Instead of std::string str;
4
std_string str; // From x86-64/contracts/libstd/stl_string.hpp
5
std::basic_string<char, std::char_traits<char>, stl_allocator<char>> str;
6
7
// Instead of std::vector<int> vec;
8
std::vector<int, stl_allocator<int>> vec;
9
10
// Instead of std::map<std::string, int> map;
11
std::map<
12
std_string, int,
13
std::less<std_string>,
14
stl_allocator<std::pair<const std_string, int>>
15
> map;
Copied!
Last modified 1yr ago