Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--map/framework.cpp11
-rw-r--r--std/tuple.hpp31
2 files changed, 37 insertions, 5 deletions
diff --git a/map/framework.cpp b/map/framework.cpp
index 7ec502eb2f..01a3fc11f7 100644
--- a/map/framework.cpp
+++ b/map/framework.cpp
@@ -95,6 +95,7 @@
#include "std/algorithm.hpp"
#include "std/bind.hpp"
#include "std/target_os.hpp"
+#include "std/tuple.hpp"
#include "api/internal/c/api-client-internals.h"
#include "api/src/c/api-client.h"
@@ -1442,11 +1443,11 @@ search::DisplayedCategories const & Framework::GetDisplayedCategories()
city = m_cityFinder->GetCityName(*position, StringUtf8Multilang::kEnglishCode);
// Apply sponsored modifiers.
- std::vector<std::unique_ptr<SponsoredCategoryModifier>> modifiers;
- modifiers.push_back(std::make_unique<LuggageHeroModifier>(city));
- modifiers.push_back(std::make_unique<Fc2018Modifier>(city));
- for (auto & modifier : modifiers)
- m_displayedCategories->Modify(*modifier);
+ tuple<LuggageHeroModifier, Fc2018Modifier> modifiers(city, city);
+ for_each_tuple(modifiers, [&](size_t, SponsoredCategoryModifier & modifier)
+ {
+ m_displayedCategories->Modify(modifier);
+ });
return *m_displayedCategories;
}
diff --git a/std/tuple.hpp b/std/tuple.hpp
index 9e05d40bc4..b24361c793 100644
--- a/std/tuple.hpp
+++ b/std/tuple.hpp
@@ -5,11 +5,42 @@
#endif
#include <tuple>
+#include <type_traits>
using std::tuple;
using std::make_tuple;
using std::get;
+
+template <size_t I = 0, typename FnT, typename... Tp>
+typename std::enable_if<I == sizeof...(Tp), void>::type
+for_each_tuple(std::tuple<Tp...> &, FnT &&)
+{
+}
+
+template <size_t I = 0, typename FnT, typename... Tp>
+typename std::enable_if<I != sizeof...(Tp), void>::type
+for_each_tuple(std::tuple<Tp...> & t, FnT && fn)
+{
+ fn(I, std::get<I>(t));
+ for_each_tuple<I + 1, FnT, Tp...>(t, std::forward<FnT>(fn));
+}
+
+template <size_t I = 0, typename FnT, typename... Tp>
+typename std::enable_if<I == sizeof...(Tp), void>::type
+for_each_tuple_const(std::tuple<Tp...> const &, FnT &&)
+{
+}
+
+template <size_t I = 0, typename FnT, typename... Tp>
+typename std::enable_if<I != sizeof...(Tp), void>::type
+for_each_tuple_const(std::tuple<Tp...> const & t, FnT && fn)
+{
+ fn(I, std::get<I>(t));
+ for_each_tuple_const<I + 1, FnT, Tp...>(t, std::forward<FnT>(fn));
+}
+
+
#ifdef DEBUG_NEW
#define new DEBUG_NEW
#endif