summaryrefslogtreecommitdiffstats
path: root/src/Generating
diff options
context:
space:
mode:
Diffstat (limited to 'src/Generating')
-rw-r--r--src/Generating/BioGen.cpp6
-rw-r--r--src/Generating/IntGen.h30
2 files changed, 24 insertions, 12 deletions
diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp
index a830f6a43..c9561cc09 100644
--- a/src/Generating/BioGen.cpp
+++ b/src/Generating/BioGen.cpp
@@ -1000,9 +1000,9 @@ public:
std::make_shared<cIntGenReplaceRandomly<6>> (a_Seed + 101, bgIce, bgTemperate, 150,
std::make_shared<cIntGenAddIslands <6>> (a_Seed + 2000, 200,
std::make_shared<cIntGenSetRandomly <6>> (a_Seed + 9, 50, bgOcean,
- std::make_shared<cIntGenZoom <6>> (a_Seed + 10,
- std::make_shared<cIntGenLandOcean <5>> (a_Seed + 100, 30
- )))))))))))))))))))))))))))))));
+ std::make_shared<cIntGenLandOcean <5>> (a_Seed + 100, 30)
+ >> MakeIntGen<cIntGenZoom <6>> (a_Seed + 10)
+ )))))))))))))))))))))))))))));
m_Gen =
std::make_shared<cIntGenSmooth <16>>(a_Seed,
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>