summaryrefslogtreecommitdiffstats
path: root/src/Generating/IntGen.h
diff options
context:
space:
mode:
authorTycho <work.tycho+git@gmail.com>2015-03-10 23:19:03 +0100
committerTycho <work.tycho+git@gmail.com>2015-03-10 23:19:03 +0100
commitff785188f943c0b0ab6a39aec4cf3ca4c54a2d95 (patch)
tree0cd2953fd4cc479f157486423e5d40991ddacc74 /src/Generating/IntGen.h
parentFixed Style (diff)
downloadcuberite-ff785188f943c0b0ab6a39aec4cf3ca4c54a2d95.tar
cuberite-ff785188f943c0b0ab6a39aec4cf3ca4c54a2d95.tar.gz
cuberite-ff785188f943c0b0ab6a39aec4cf3ca4c54a2d95.tar.bz2
cuberite-ff785188f943c0b0ab6a39aec4cf3ca4c54a2d95.tar.lz
cuberite-ff785188f943c0b0ab6a39aec4cf3ca4c54a2d95.tar.xz
cuberite-ff785188f943c0b0ab6a39aec4cf3ca4c54a2d95.tar.zst
cuberite-ff785188f943c0b0ab6a39aec4cf3ca4c54a2d95.zip
Diffstat (limited to 'src/Generating/IntGen.h')
-rw-r--r--src/Generating/IntGen.h30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/Generating/IntGen.h b/src/Generating/IntGen.h
index 4fce3ba08..1ffc15c6b 100644
--- a/src/Generating/IntGen.h
+++ b/src/Generating/IntGen.h
@@ -70,15 +70,20 @@ public:
};
-template<size_t size, class... Args>
-struct PackToInt
-{
- enum
- {
- value = size - sizeof...(Args),
- };
+// Code adapted from http://stackoverflow.com/questions/7858817/unpacking-a-tuple-to-call-a-matching-function-pointer
+
+template<int ...>
+struct seq { };
+
+template<int N, int ...S>
+struct gens : gens<N-1, N-1, S...> { };
+
+template<int ...S>
+struct gens<0, S...> {
+ typedef seq<S...> type;
};
+
template<class Gen, class... Args>
class cIntGenFactory
{
@@ -91,16 +96,23 @@ public:
m_args(std::make_tuple<Args...>(std::forward<Args>(a_args)...))
{
}
-
+
template <class LhsGen>
std::shared_ptr<Gen> construct(LhsGen&& lhs)
{
- return std::make_shared<Gen>(std::get<PackToInt<sizeof...(Args), Args>::value>(m_args)..., std::forward<LhsGen>(lhs));
+ return construct_impl<LhsGen>(std::forward<LhsGen>(lhs), typename gens<sizeof...(Args)>::type());
}
+
private:
std::tuple<Args...> m_args;
+ template <class LhsGen, int... S>
+ std::shared_ptr<Gen> construct_impl(LhsGen&& lhs, seq<S...>)
+ {
+ return std::make_shared<Gen>(std::get<S>(m_args)..., std::forward<LhsGen>(lhs));
+ }
+
};
template<class T, class RhsGen, class... Args>