Skip to content

Instantly share code, notes, and snippets.

@plonk
Created March 16, 2013 05:38
Show Gist options
  • Select an option

  • Save plonk/5175144 to your computer and use it in GitHub Desktop.

Select an option

Save plonk/5175144 to your computer and use it in GitHub Desktop.
可変長引数テンプレート習作
#include <iostream>
template <typename T>
T inject_plus(T v)
{ return v; }
template <typename T, typename ... Rest>
T inject_plus(T v, Rest ... rest)
{
return v + inject_plus(rest...);
}
int main()
{
std::string hello("Hello");
std::string world(" World");
std::cout << inject_plus(1, 10, 100, 1000) << std::endl;
std::cout << inject_plus(3.0, 0.14, 0.00159) << std::endl;
std::cout << inject_plus(hello, world) << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment