Skip to content

Instantly share code, notes, and snippets.

@thiagomg
Created May 9, 2015 01:15
Show Gist options
  • Save thiagomg/e0eb1b5b0ebbd691a506 to your computer and use it in GitHub Desktop.
Save thiagomg/e0eb1b5b0ebbd691a506 to your computer and use it in GitHub Desktop.
func_temp_gen.cpp
#include <vector>
#include <cstdio>
using namespace std;
//this function will be generated
int c_accum_i(vector<int> &v)
{
int ret{};
for(const auto &i : v) {
ret += i;
}
return ret;
}
//this function will be generated
double c_accum_d(vector<double> &v)
{
double ret{};
for(const auto &i : v) {
ret += i;
}
return ret;
}
//no function will be generated
template<typename T>
T cpp_accum(vector<T> &v)
{
T ret{};
for(const auto &i : v) {
ret += i;
}
return ret;
}
//no function will be generated
struct Utils {
template<typename T>
T cpp_class_accum(vector<T> &v)
{
T ret{};
for(const auto &i : v) {
ret += i;
}
return ret;
}
virtual ~Utils() { }
};
int main(int argc, char *argv[])
{
vector<int> vi{ 1, 2, 3 };
vector<double> vd{ 1.0, 2.0, 3.0 };
Utils u;
printf("%d\r\n", c_accum_i(vi));
printf("%d\r\n", cpp_accum(vi));
printf("%f\r\n", cpp_accum(vd));
printf("%d\r\n", u.cpp_class_accum(vi));
return 0;
}
//g++ -std=c++14 -c func_temp_gen.cpp
//nm -C func_temp_gen.o | grep accum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment