~williamvds/linking-by-example

343d4246dc4baa508e048f78c96e10329e657b08 — williamvds 2 months ago 624f9f1
Explicit template instantiation
M library.cpp => library.cpp +8 -0
@@ 1,5 1,13 @@
#include "library.hpp"

template <typename T>
T square(T num) {
    return num * num;
}

template int square<>(int);
template long square<>(long);

int operand = 5;

int square_10() {

M library.hpp => library.hpp +1 -3
@@ 1,8 1,6 @@
#pragma once

template <typename T>
auto square(T num) {
    return num * num;
}
extern T square(T num);

extern int operand;

M results/executable symbols => results/executable symbols +3 -3
@@ 16,10 16,10 @@ $ nm --demangle ./build/example
                 w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable
                 U __libc_start_main@GLIBC_2.34
0000000000001138 T main
000000000000114a T main
0000000000004010 D operand
0000000000001020 T _start
0000000000004018 D __TMC_END__
0000000000001129 W auto square<int>(int)
000000000000114e W auto square<long>(long)
0000000000001129 W int square<int>(int)
0000000000001138 W long square<long>(long)
0000000000001119 T square_10()

M results/library.cpp.o symbols => results/library.cpp.o symbols +2 -1
@@ 1,4 1,5 @@
$ nm --demangle ./build/CMakeFiles/example.dir/library.cpp.o
0000000000000000 D operand
0000000000000000 W auto square<int>(int)
0000000000000000 W int square<int>(int)
0000000000000000 W long square<long>(long)
0000000000000000 T square_10()

M results/main.cpp.o symbols => results/main.cpp.o symbols +1 -1
@@ 1,4 1,4 @@
$ nm --demangle ./build/CMakeFiles/example.dir/main.cpp.o
0000000000000000 T main
                 U operand
0000000000000000 W auto square<long>(long)
                 U long square<long>(long)