From 51dbe0fe954e1f11629c05249f403df9d3807936 Mon Sep 17 00:00:00 2001 From: Maxim Pimenov Date: Thu, 30 Nov 2017 16:31:49 +0300 Subject: [PATCH] Review fixes. --- generator/search_index_builder.cpp | 2 +- search/processor.cpp | 4 ++-- search/query_params.cpp | 4 ++-- search/query_params.hpp | 14 +++++++++----- search/search_tests/keyword_matcher_test.cpp | 1 + 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/generator/search_index_builder.cpp b/generator/search_index_builder.cpp index b442c23423..62edb1c99e 100644 --- a/generator/search_index_builder.cpp +++ b/generator/search_index_builder.cpp @@ -178,7 +178,7 @@ struct FeatureNameInserter }); } - CHECK_GREATER(search::kMaxNumTokens, 0, ()); + static_assert(search::kMaxNumTokens > 0, ""); size_t const maxTokensCount = search::kMaxNumTokens - 1; if (tokens.size() > maxTokensCount) { diff --git a/search/processor.cpp b/search/processor.cpp index 79d32c70d3..ca066ded7c 100644 --- a/search/processor.cpp +++ b/search/processor.cpp @@ -119,7 +119,7 @@ void SendStatistics(SearchParams const & params, m2::RectD const & viewport, Res } // Removes all full-token stop words from |tokens|. -// Does nothing if all tokens in are non-prefix stop words. +// Does nothing if all tokens are non-prefix stop words. void RemoveStopWordsIfNeeded(QueryTokens & tokens, strings::UniString & prefix) { size_t numStopWords = 0; @@ -252,8 +252,8 @@ void Processor::SetQuery(string const & query) } } + static_assert(kMaxNumTokens > 0, ""); size_t const maxTokensCount = kMaxNumTokens - 1; - ASSERT_GREATER(maxTokensCount, 0, ()); if (m_tokens.size() > maxTokensCount) { m_tokens.resize(maxTokensCount); diff --git a/search/query_params.cpp b/search/query_params.cpp index c3016a2334..85ea05811d 100644 --- a/search/query_params.cpp +++ b/search/query_params.cpp @@ -5,7 +5,7 @@ #include "indexer/feature_impl.hpp" -#include +#include using namespace std; @@ -52,7 +52,7 @@ private: } // namespace // QueryParams::Token ------------------------------------------------------------------------------ -void QueryParams::Token::AddSynonym(std::string const & s) +void QueryParams::Token::AddSynonym(string const & s) { AddSynonym(strings::MakeUniString(s)); } diff --git a/search/query_params.hpp b/search/query_params.hpp index 6a2dbdff09..44dd656ffc 100644 --- a/search/query_params.hpp +++ b/search/query_params.hpp @@ -8,9 +8,11 @@ #include "base/small_set.hpp" #include "base/string_utils.hpp" +#include #include #include #include +#include #include namespace search @@ -34,17 +36,19 @@ public: // Calls |fn| on the original token and on synonyms. template - typename enable_if::type, void>::value>::type ForEach( - Fn && fn) const + typename std::enable_if< + std::is_same::type, void>::value>::type + ForEach(Fn && fn) const { fn(m_original); - for_each(m_synonyms.begin(), m_synonyms.end(), std::forward(fn)); + std::for_each(m_synonyms.begin(), m_synonyms.end(), std::forward(fn)); } // Calls |fn| on the original token and on synonyms until |fn| return false. template - typename enable_if::type, bool>::value>::type ForEach( - Fn && fn) const + typename std::enable_if< + std::is_same::type, bool>::value>::type + ForEach(Fn && fn) const { if (!fn(m_original)) return; diff --git a/search/search_tests/keyword_matcher_test.cpp b/search/search_tests/keyword_matcher_test.cpp index d26c8fc051..69f483c4a2 100644 --- a/search/search_tests/keyword_matcher_test.cpp +++ b/search/search_tests/keyword_matcher_test.cpp @@ -259,6 +259,7 @@ string GetManyTokens(string tokenPrefix, int tokenCount, bool countForward = tru UNIT_TEST(KeywordMatcher_QueryTooLong) { + static_assert(kMaxNumTokens >= 2, ""); for (int queryLength = kMaxNumTokens - 2; queryLength <= kMaxNumTokens + 2; ++queryLength) { string const query = GetManyTokens("Q", queryLength);