Template Naming Convention

When creating bindings for a templated class tolc will choose a name based on the template parameters. For example:

template <typename T>
class Example {
public:
T f(T type) {
    return type;
}
};

template class Example<int>;

The specialized class Example<int> will be available from javascript as Example_int:

const loadMyLib = require('./build/MyLib');

loadm().then(MyLib => {
    example = new MyLib.Example_int();
    // Prints 5
    print(example.f(5))
    example.delete();
});

Multiple template parameters are separated with an underscore (_). The names are meant to be as predictable as possible. The rules are:

  • std:: is removed from any standard library type.
  • _ is removed from any standard library type.
  • User defined types are left untouched (i.e. the class MyNamespace::MyClass will result in appending MyClass).

Type to string conversions

C++ type Resulting name
std::array array
std::complex complex
std::deque deque
std::filesystem::path path
std::forward_list forwardlist
std::function function
std::list list
std::map map
std::multimap multimap
std::multiset multiset
std::optional optional
std::pair pair
std::priority_queue priorityqueue
std::queue queue
std::set set
std::shared_ptr sharedptr
std::stack stack
std::tuple tuple
std::unique_ptr uniqueptr
std::unordered_map unorderedmap
std::unordered_multimap unorderedmultimap
std::unordered_multiset unorderedmultiset
std::unordered_set unorderedset
std::valarray valarray
std::variant variant
std::vector vector
bool bool
char char
char16_t char16t
char32_t char32t
double double
float float
int int
Integral Integral literal*
long double longdouble
long int longint
long long int longlongint
short int shortint
signed char signedchar
string string
string_view stringview
unsigned char unsignedchar
unsigned int unsignedint
unsigned long int unsignedlongint
unsigned long long int unsignedlonglongint
unsigned short int unsignedshortint
wchar_t wchart

* For example the 3 in MyClass<std::array<int, 3>> results in MyClass_array_int_3.