Skip to content

Instantly share code, notes, and snippets.

@wallstop
Last active August 29, 2015 14:07
Show Gist options
  • Save wallstop/b04a93b095b443b0f3ef to your computer and use it in GitHub Desktop.
Save wallstop/b04a93b095b443b0f3ef to your computer and use it in GitHub Desktop.
Simple Create Pattern
#pragma once
#include <utility>
template <typename T, typename ... Args>
T create(Args... args)
{
return std::move(T(args...));
}
template <>
int create<int>() // Only override default constructor for int
{
return 9001;
}
// Override templates as need be
#include "Create.h"
int main()
{
int i = create<int>(); // Should be 9001
int b = create<int>(1);
int* c = new int(create<int>(500));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment