diff options
author | Sergey Yershov <syershov@maps.me> | 2016-12-17 00:42:38 +0300 |
---|---|---|
committer | Sergey Yershov <syershov@maps.me> | 2016-12-28 15:24:51 +0300 |
commit | 20c0eb77e37e8148e37ca50edb3b6c5bab160198 (patch) | |
tree | c0a68233c3a9a0799a2367a9bf4b03825c39834a /base | |
parent | 8846a23bc3b464f523621aae19396a68839e443f (diff) |
Remove using std from base
Diffstat (limited to 'base')
92 files changed, 704 insertions, 1624 deletions
diff --git a/base/CMakeLists.txt b/base/CMakeLists.txt index e71d7f4a6b..70b0832656 100644 --- a/base/CMakeLists.txt +++ b/base/CMakeLists.txt @@ -2,7 +2,6 @@ project(base) set( SRC - SRC_FIRST.hpp array_adapters.hpp assert.hpp base.cpp @@ -14,10 +13,6 @@ set( collection_cast.hpp condition.cpp condition.hpp -# condition_bada.cpp - condition_posix.cpp -# condition_windows_native.cpp - const_helper.hpp deferred_task.cpp deferred_task.hpp dfa_helpers.hpp @@ -38,8 +33,6 @@ set( mutex.hpp newtype.hpp normalize_unicode.cpp - object_tracker.cpp - object_tracker.hpp observer_list.hpp range_iterator.hpp ref_counted.hpp @@ -63,7 +56,6 @@ set( strings_bundle.hpp sunrise_sunset.cpp sunrise_sunset.hpp - swap.hpp thread.cpp thread.hpp thread_checker.cpp @@ -73,7 +65,6 @@ set( threaded_container.cpp threaded_container.hpp threaded_list.hpp - threaded_priority_queue.hpp internal/message.cpp internal/message.hpp timegm.cpp @@ -82,7 +73,6 @@ set( timer.hpp uni_string_dfa.cpp uni_string_dfa.hpp - worker_thread.hpp ) add_library(${PROJECT_NAME} ${SRC}) diff --git a/base/SRC_FIRST.hpp b/base/SRC_FIRST.hpp deleted file mode 100644 index b948f256c9..0000000000 --- a/base/SRC_FIRST.hpp +++ /dev/null @@ -1,2 +0,0 @@ -#pragma once -#include "base/base.hpp" diff --git a/base/assert.hpp b/base/assert.hpp index de51536c67..d4f73c44d6 100644 --- a/base/assert.hpp +++ b/base/assert.hpp @@ -3,13 +3,13 @@ #include "base/internal/message.hpp" #include "base/src_point.hpp" -#include "std/string.hpp" +#include <string> namespace my { // Called when ASSERT, CHECK or VERIFY failed. - typedef void (*AssertFailedFn)(SrcPoint const &, string const &); + typedef void (*AssertFailedFn)(SrcPoint const &, std::string const &); extern AssertFailedFn OnAssertFailed; /// @return Pointer to previous message function. diff --git a/base/base.cpp b/base/base.cpp index dc93a19ea2..53d5c522f5 100644 --- a/base/base.cpp +++ b/base/base.cpp @@ -3,19 +3,19 @@ #include "base/exception.hpp" #include "std/target_os.hpp" -#include "std/iostream.hpp" +#include <iostream> #include <cassert> #include <cstdlib> namespace my { - void OnAssertFailedDefault(SrcPoint const & srcPoint, string const & msg) + void OnAssertFailedDefault(SrcPoint const & srcPoint, std::string const & msg) { - std::cerr << "ASSERT FAILED" << endl - << srcPoint.FileName() << ":" << srcPoint.Line() << endl - << msg << endl; + std::cerr << "ASSERT FAILED" << std::endl + << srcPoint.FileName() << ":" << srcPoint.Line() << std::endl + << msg << std::endl; #ifdef DEBUG assert(false); diff --git a/base/base.hpp b/base/base.hpp index 550dd538d6..e8543cb02e 100644 --- a/base/base.hpp +++ b/base/base.hpp @@ -1,6 +1,6 @@ #pragma once -#include "std/cstdint.hpp" +#include <cstdint> #if defined(DEBUG) || defined(_DEBUG) || defined(NRELEASE) #define MY_DEBUG_DEFINED 1 diff --git a/base/base.pro b/base/base.pro index 31f3f5bd88..aa42754cc5 100644 --- a/base/base.pro +++ b/base/base.pro @@ -18,7 +18,6 @@ SOURCES += \ logging.cpp \ lower_case.cpp \ normalize_unicode.cpp \ - object_tracker.cpp \ shared_buffer_manager.cpp \ src_point.cpp \ string_format.cpp \ @@ -29,7 +28,6 @@ SOURCES += \ thread_checker.cpp \ thread_pool.cpp \ threaded_container.cpp \ - time_samples.cpp \ timegm.cpp \ timer.cpp \ uni_string_dfa.cpp \ @@ -45,7 +43,6 @@ HEADERS += \ cancellable.hpp \ collection_cast.hpp \ condition.hpp \ - const_helper.hpp \ deferred_task.hpp \ dfa_helpers.hpp \ exception.hpp \ @@ -60,7 +57,6 @@ HEADERS += \ mem_trie.hpp \ mutex.hpp \ newtype.hpp \ - object_tracker.hpp \ observer_list.hpp \ range_iterator.hpp \ ref_counted.hpp \ @@ -79,15 +75,12 @@ HEADERS += \ string_utils.hpp \ strings_bundle.hpp \ sunrise_sunset.hpp \ - swap.hpp \ thread.hpp \ thread_checker.hpp \ thread_pool.hpp \ threaded_container.hpp \ threaded_list.hpp \ threaded_priority_queue.hpp \ - time_samples.hpp \ timegm.hpp \ timer.hpp \ uni_string_dfa.hpp \ - worker_thread.hpp \ diff --git a/base/base_tests/CMakeLists.txt b/base/base_tests/CMakeLists.txt index 0fa0ec6b3e..7d3106daaa 100644 --- a/base/base_tests/CMakeLists.txt +++ b/base/base_tests/CMakeLists.txt @@ -10,7 +10,6 @@ set( cache_test.cpp collection_cast_test.cpp condition_test.cpp - const_helper.cpp containers_test.cpp levenshtein_dfa_test.cpp logging_test.cpp @@ -35,7 +34,6 @@ set( timegm_test.cpp timer_test.cpp uni_string_dfa_test.cpp - worker_thread_test.cpp ) omim_add_test(${PROJECT_NAME} ${SRC}) diff --git a/base/base_tests/assert_test.cpp b/base/base_tests/assert_test.cpp index 7056d244d7..0df32cc5df 100644 --- a/base/base_tests/assert_test.cpp +++ b/base/base_tests/assert_test.cpp @@ -1,4 +1,3 @@ -#include "base/SRC_FIRST.hpp" #include "testing/testing.hpp" #include "base/base.hpp" diff --git a/base/base_tests/base_tests.pro b/base/base_tests/base_tests.pro index c8708b84d4..32049b5282 100644 --- a/base/base_tests/base_tests.pro +++ b/base/base_tests/base_tests.pro @@ -20,7 +20,6 @@ SOURCES += \ cache_test.cpp \ collection_cast_test.cpp \ condition_test.cpp \ - const_helper.cpp \ containers_test.cpp \ levenshtein_dfa_test.cpp \ logging_test.cpp \ @@ -45,6 +44,5 @@ SOURCES += \ timegm_test.cpp \ timer_test.cpp \ uni_string_dfa_test.cpp \ - worker_thread_test.cpp \ HEADERS += diff --git a/base/base_tests/bits_test.cpp b/base/base_tests/bits_test.cpp index bded2a18ec..c7184b6055 100644 --- a/base/base_tests/bits_test.cpp +++ b/base/base_tests/bits_test.cpp @@ -1,4 +1,3 @@ -#include "base/SRC_FIRST.hpp" #include "testing/testing.hpp" #include "base/bits.hpp" @@ -29,7 +28,7 @@ UNIT_TEST(PopcountArray32) { for (uint32_t j = 0; j < 2777; ++j) { - vector<uint32_t> v(j / 10); + std::vector<uint32_t> v(j / 10); for (size_t i = 0; i < v.size(); ++i) v[i] = ((uint32_t(rand()) & 255) << 24) + ((rand() & 255) << 16) + ((rand() & 255) << 8) + (rand() & 255); diff --git a/base/base_tests/buffer_vector_test.cpp b/base/base_tests/buffer_vector_test.cpp index 96a0a62a25..f9fd8f8130 100644 --- a/base/base_tests/buffer_vector_test.cpp +++ b/base/base_tests/buffer_vector_test.cpp @@ -144,21 +144,21 @@ UNIT_TEST(BufferVectorInsert) for (size_t insertPos = 0; insertPos <= initialLength; ++insertPos) { buffer_vector<char, 5> b; - vector<char> v; + std::vector<char> v; for (size_t i = 0; i < initialLength; ++i) { b.push_back('A' + i); v.push_back('A' + i); } - vector<int> dataToInsert(insertLength); + std::vector<int> dataToInsert(insertLength); for (size_t i = 0; i < insertLength; ++i) dataToInsert[i] = 'a' + i; b.insert(b.begin() + insertPos, dataToInsert.begin(), dataToInsert.end()); v.insert(v.begin() + insertPos, dataToInsert.begin(), dataToInsert.end()); - vector<char> result(b.begin(), b.end()); + std::vector<char> result(b.begin(), b.end()); TEST_EQUAL(v, result, (initialLength, insertLength, insertPos)); } } @@ -202,21 +202,21 @@ UNIT_TEST(BufferVectorAppend) for (size_t insertLength = 0; insertLength < 20; ++insertLength) { buffer_vector<char, 5> b; - vector<char> v; + std::vector<char> v; for (size_t i = 0; i < initialLength; ++i) { b.push_back('A' + i); v.push_back('A' + i); } - vector<int> dataToInsert(insertLength); + std::vector<int> dataToInsert(insertLength); for (size_t i = 0; i < insertLength; ++i) dataToInsert[i] = 'a' + i; b.append(dataToInsert.begin(), dataToInsert.end()); v.insert(v.end(), dataToInsert.begin(), dataToInsert.end()); - vector<char> result(b.begin(), b.end()); + std::vector<char> result(b.begin(), b.end()); TEST_EQUAL(v, result, (initialLength, insertLength)); } } @@ -325,11 +325,11 @@ UNIT_TEST(BufferVectorMove) v1.emplace_back("2"); TestVector(v1, 3); - VectorT v2(move(v1)); + VectorT v2(std::move(v1)); TestVector(v2, 3); VectorT().swap(v1); - v1 = move(v2); + v1 = std::move(v2); TestVector(v1, 3); } diff --git a/base/base_tests/cache_test.cpp b/base/base_tests/cache_test.cpp index 0073c65e59..e9d8f2e65e 100644 --- a/base/base_tests/cache_test.cpp +++ b/base/base_tests/cache_test.cpp @@ -18,7 +18,7 @@ public: m_v.push_back(c); } - vector<char> m_v; + std::vector<char> m_v; private: DISALLOW_COPY(SimpleFunctor); @@ -28,7 +28,7 @@ private: class SimpleMovableFunctor { public: - SimpleMovableFunctor(vector<char> * v) : m_v(v) {} + SimpleMovableFunctor(std::vector<char> * v) : m_v(v) {} // movable SimpleMovableFunctor(SimpleMovableFunctor && other) @@ -43,7 +43,7 @@ public: } private: - vector<char> * m_v; + std::vector<char> * m_v; DISALLOW_COPY(SimpleMovableFunctor); }; @@ -85,9 +85,9 @@ UNIT_TEST(CacheSmoke_0) bool found = true; cache.Find(0, found); TEST(!found, ()); - vector<char> v; + std::vector<char> v; cache.ForEachValue(MakeBackInsertFunctor(v)); - TEST_EQUAL(v, vector<char>(8, 0), ()); + TEST_EQUAL(v, std::vector<char>(8, 0), ()); } UNIT_TEST(CacheSmoke_1) @@ -95,7 +95,7 @@ UNIT_TEST(CacheSmoke_1) my::Cache<uint32_t, char> cache(3); // it contains 2^3=8 elements SimpleFunctor f; cache.ForEachValue(f); // f passed by reference - TEST_EQUAL(f.m_v, vector<char>(8, 0), ()); + TEST_EQUAL(f.m_v, std::vector<char>(8, 0), ()); } UNIT_TEST(CacheSmoke_2) @@ -103,7 +103,7 @@ UNIT_TEST(CacheSmoke_2) my::Cache<uint32_t, char> cache(3); // it contains 2^3=8 elements SimpleFunctor f; cache.ForEachValue(ref(f)); // f passed by reference - TEST_EQUAL(f.m_v, vector<char>(8, 0), ()); + TEST_EQUAL(f.m_v, std::vector<char>(8, 0), ()); } UNIT_TEST(CacheSmoke_3) @@ -142,7 +142,7 @@ UNIT_TEST(CacheSmoke_4) my::CacheWithStat<uint32_t, char> cache(3); // it contains 2^3=8 elements SimpleFunctor f; cache.ForEachValue(f); // f passed by reference - TEST_EQUAL(f.m_v, vector<char>(8, 0), ()); + TEST_EQUAL(f.m_v, std::vector<char>(8, 0), ()); } UNIT_TEST(CacheSmoke_5) @@ -150,15 +150,15 @@ UNIT_TEST(CacheSmoke_5) my::CacheWithStat<uint32_t, char> cache(3); // it contains 2^3=8 elements SimpleFunctor f; cache.ForEachValue(ref(f)); // f passed by reference - TEST_EQUAL(f.m_v, vector<char>(8, 0), ()); + TEST_EQUAL(f.m_v, std::vector<char>(8, 0), ()); } UNIT_TEST(CacheSmoke_6) { my::CacheWithStat<uint32_t, char> cache(3); // it contains 2^3=8 elements - vector<char> v; + std::vector<char> v; cache.ForEachValue(SimpleMovableFunctor(&v)); - TEST_EQUAL(v, vector<char>(8, 0), ()); + TEST_EQUAL(v, std::vector<char>(8, 0), ()); } UNIT_TEST(Cache_Init) diff --git a/base/base_tests/condition_test.cpp b/base/base_tests/condition_test.cpp index 45c8e6216c..b1e1b65739 100644 --- a/base/base_tests/condition_test.cpp +++ b/base/base_tests/condition_test.cpp @@ -1,11 +1,10 @@ -#include "base/SRC_FIRST.hpp" #include "testing/testing.hpp" #include "base/thread.hpp" #include "base/threaded_list.hpp" #include "base/condition.hpp" - #include "base/logging.hpp" +#include "base/stl_add.hpp" struct ConditionThread : public threads::IRoutine { @@ -25,10 +24,10 @@ UNIT_TEST(Condition_Test) ThreadedList<int> l; threads::Thread t0; - t0.Create(make_unique<ConditionThread>(&l)); + t0.Create(my::make_unique<ConditionThread>(&l)); threads::Thread t1; - t1.Create(make_unique<ConditionThread>(&l)); + t1.Create(my::make_unique<ConditionThread>(&l)); l.Cancel(); t0.Join(); diff --git a/base/base_tests/const_helper.cpp b/base/base_tests/const_helper.cpp deleted file mode 100644 index b46ce9dc93..0000000000 --- a/base/base_tests/const_helper.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "base/SRC_FIRST.hpp" -#include "testing/testing.hpp" - -#include "base/const_helper.hpp" -#include "std/typeinfo.hpp" - -UNIT_TEST(ConstHelper) -{ - TEST_EQUAL(typeid(my::PropagateConst<int, char>::type *).name(), typeid(char *).name(), ()); - TEST_EQUAL(typeid(my::PropagateConst<int, void>::type *).name(), typeid(void *).name(), ()); - TEST_EQUAL(typeid(my::PropagateConst<int const, char>::type *).name(), - typeid(char const *).name(), ()); - TEST_EQUAL(typeid(my::PropagateConst<int const, void>::type *).name(), - typeid(void const *).name(), ()); - TEST_EQUAL(typeid(my::PropagateConst<int, char const>::type *).name(), - typeid(char const *).name(), ()); - TEST_EQUAL(typeid(my::PropagateConst<int, void const>::type *).name(), - typeid(void const *).name(), ()); - TEST_EQUAL(typeid(my::PropagateConst<int const, char const>::type *).name(), - typeid(char const *).name(), ()); - TEST_EQUAL(typeid(my::PropagateConst<int const, void const>::type *).name(), - typeid(void const *).name(), ()); -} diff --git a/base/base_tests/containers_test.cpp b/base/base_tests/containers_test.cpp index 1ed3e807ab..577cdfd24b 100644 --- a/base/base_tests/containers_test.cpp +++ b/base/base_tests/containers_test.cpp @@ -1,4 +1,3 @@ -#include "base/SRC_FIRST.hpp" #include "testing/testing.hpp" #include "base/limited_priority_queue.hpp" diff --git a/base/base_tests/logging_test.cpp b/base/base_tests/logging_test.cpp index b3776da773..cb6439ef18 100644 --- a/base/base_tests/logging_test.cpp +++ b/base/base_tests/logging_test.cpp @@ -1,4 +1,3 @@ -#include "base/SRC_FIRST.hpp" #include "testing/testing.hpp" #include "base/logging.hpp" diff --git a/base/base_tests/ref_counted_tests.cpp b/base/base_tests/ref_counted_tests.cpp index f1863eb499..f7f690fa80 100644 --- a/base/base_tests/ref_counted_tests.cpp +++ b/base/base_tests/ref_counted_tests.cpp @@ -58,7 +58,7 @@ UNIT_TEST(RefCounted_Smoke) TEST_EQUAL(2, a->NumRefs(), ()); TEST(!destroyed, ()); - RefCountPtr<Resource> d(move(b)); + RefCountPtr<Resource> d(std::move(b)); TEST(b.Get() == nullptr, ()); TEST(a.Get() == d.Get(), ()); TEST_EQUAL(2, a->NumRefs(), ()); diff --git a/base/base_tests/regexp_test.cpp b/base/base_tests/regexp_test.cpp index bd13b9d1f4..a1f7474505 100644 --- a/base/base_tests/regexp_test.cpp +++ b/base/base_tests/regexp_test.cpp @@ -28,7 +28,7 @@ UNIT_TEST(RegExp_ForEachMatched) { string const s = "6.66, 9.99"; - vector<string> v; + std::vector<string> v; strings::ForEachMatched(s, exp, MakeBackInsertFunctor(v)); TEST_EQUAL(v.size(), 1, ()); TEST_EQUAL(v[0], s, ()); @@ -37,7 +37,7 @@ UNIT_TEST(RegExp_ForEachMatched) { string const s1 = "6.66, 9.99"; string const s2 = "-5.55, -7.77"; - vector<string> v; + std::vector<string> v; strings::ForEachMatched(s1 + " 180 , bfuewib 365@" + s2, exp, MakeBackInsertFunctor(v)); TEST_EQUAL(v.size(), 2, ()); TEST_EQUAL(v[0], s1, ()); @@ -46,7 +46,7 @@ UNIT_TEST(RegExp_ForEachMatched) { string const s = "X6.66, 9.99"; - vector<string> v; + std::vector<string> v; strings::ForEachMatched(s, exp, MakeBackInsertFunctor(v)); TEST_EQUAL(v.size(), 1, ()); TEST_EQUAL(v[0], string(s.begin() + 1, s.end()), ()); @@ -54,7 +54,7 @@ UNIT_TEST(RegExp_ForEachMatched) { string const s = "6.66, 9.99X"; - vector<string> v; + std::vector<string> v; strings::ForEachMatched(s, exp, MakeBackInsertFunctor(v)); TEST_EQUAL(v.size(), 1, ()); TEST_EQUAL(v[0], string(s.begin(), s.end() - 1), ()); @@ -62,14 +62,14 @@ UNIT_TEST(RegExp_ForEachMatched) { string const s = "6.66X, 9.99"; - vector<string> v; + std::vector<string> v; strings::ForEachMatched(s, exp, MakeBackInsertFunctor(v)); TEST_EQUAL(v.size(), 0, ()); } { string const s = "6.66, X9.99"; - vector<string> v; + std::vector<string> v; strings::ForEachMatched(s, exp, MakeBackInsertFunctor(v)); TEST_EQUAL(v.size(), 0, ()); } diff --git a/base/base_tests/rolling_hash_test.cpp b/base/base_tests/rolling_hash_test.cpp index b96e41452a..21eb1caa1d 100644 --- a/base/base_tests/rolling_hash_test.cpp +++ b/base/base_tests/rolling_hash_test.cpp @@ -41,7 +41,7 @@ template <class RollingHasherT> void TestRollingHasher() { typedef typename RollingHasherT::hash_type hash_type; RollingHasherT hash; - vector<hash_type> hashes; + std::vector<hash_type> hashes; hashes.push_back(hash.Init(static_cast<char const *>(s), size)); for (uint32_t i = size; i < len; ++i) hashes.push_back(hash.Scroll(s[i - size], s[i])); diff --git a/base/base_tests/scope_guard_test.cpp b/base/base_tests/scope_guard_test.cpp index b66a474948..a3b9b8840d 100644 --- a/base/base_tests/scope_guard_test.cpp +++ b/base/base_tests/scope_guard_test.cpp @@ -1,4 +1,3 @@ -#include "base/SRC_FIRST.hpp" #include "testing/testing.hpp" #include "base/scope_guard.hpp" diff --git a/base/base_tests/stl_add_test.cpp b/base/base_tests/stl_add_test.cpp index ae3e8e9181..d425003cea 100644 --- a/base/base_tests/stl_add_test.cpp +++ b/base/base_tests/stl_add_test.cpp @@ -36,7 +36,7 @@ namespace UNIT_TEST(STLAdd_RemoveIfKeepValid) { { - vector<int> v; + std::vector<int> v; TEST(RemoveIfKeepValid(v.begin(), v.end(), EqualZero()) == v.end(), ()); v.push_back(1); @@ -47,7 +47,7 @@ UNIT_TEST(STLAdd_RemoveIfKeepValid) } { - vector<int> v; + std::vector<int> v; v.push_back(0); TEST(RemoveIfKeepValid(v.begin(), v.end(), EqualZero()) == v.begin(), ()); @@ -90,11 +90,11 @@ namespace { template <class T, size_t N1, size_t N2, size_t N3> void CheckAccumulateIntervals(size_t & idTest, - pair<T, T> (&arr1)[N1], - pair<T, T> (&arr2)[N2], - pair<T, T> (&arr3)[N3]) + std::pair<T, T> (&arr1)[N1], + std::pair<T, T> (&arr2)[N2], + std::pair<T, T> (&arr3)[N3]) { - vector<pair<T, T> > res; + std::vector<std::pair<T, T> > res; AccumulateIntervals1With2(arr1, arr1 + N1, arr2, arr2 + N2, back_inserter(res)); ++idTest; @@ -105,12 +105,12 @@ namespace UNIT_TEST(STLAdd_AccumulateIntervals) { - typedef pair<int, int> T; + typedef std::pair<int, int> T; size_t idTest = 0; // bound cases { - vector<T> res; + std::vector<T> res; T arr[] = { T(10, 20) }; res.clear(); diff --git a/base/base_tests/string_utils_test.cpp b/base/base_tests/string_utils_test.cpp index 6d09bd530d..8f01391353 100644 --- a/base/base_tests/string_utils_test.cpp +++ b/base/base_tests/string_utils_test.cpp @@ -44,7 +44,7 @@ UNIT_TEST(LowerUniChar) if (!semicolon) continue; string const capital = *semicolon; - istringstream stream(capital); + std::istringstream stream(capital); strings::UniChar uc; stream >> hex >> uc; ++semicolon; @@ -296,7 +296,7 @@ UNIT_TEST(to_string) TEST_EQUAL(strings::to_string(123456789123456789ULL), "123456789123456789", ()); TEST_EQUAL(strings::to_string(-987654321987654321LL), "-987654321987654321", ()); - uint64_t const n = numeric_limits<uint64_t>::max(); + uint64_t const n = std::numeric_limits<uint64_t>::max(); TEST_EQUAL(strings::to_string(n), "18446744073709551615", ()); } @@ -454,9 +454,9 @@ UNIT_TEST(SimpleTokenizer) UNIT_TEST(Tokenize) { { - initializer_list<string> expected{"acb", "def", "ghi"}; - TEST_EQUAL(strings::Tokenize<vector>("acb def ghi", " " /* delims */), vector<string>(expected), ()); - TEST_EQUAL(strings::Tokenize<set>("acb def ghi", " " /* delims */), set<string>(expected), ()); + std::initializer_list<string> expected{"acb", "def", "ghi"}; + TEST_EQUAL(strings::Tokenize<std::vector>("acb def ghi", " " /* delims */), std::vector<std::string>(expected), ()); + TEST_EQUAL(strings::Tokenize<std::set>("acb def ghi", " " /* delims */), std::set<std::string>(expected), ()); } } diff --git a/base/base_tests/threaded_list_test.cpp b/base/base_tests/threaded_list_test.cpp index 5deeba40ef..806e155823 100644 --- a/base/base_tests/threaded_list_test.cpp +++ b/base/base_tests/threaded_list_test.cpp @@ -1,11 +1,9 @@ -#include "base/SRC_FIRST.hpp" #include "testing/testing.hpp" #include "base/threaded_list.hpp" -#include "base/threaded_priority_queue.hpp" #include "base/thread.hpp" - #include "base/logging.hpp" +#include "base/stl_add.hpp" #include "std/mutex.hpp" @@ -13,10 +11,10 @@ struct ThreadedListProcessor : public threads::IRoutine { ThreadedList<int> & m_p; mutex & m_resMutex; - list<int> & m_res; + std::list<int> & m_res; int m_id; - ThreadedListProcessor(ThreadedList<int> & p, mutex & resMutex, list<int> & res, int id) + ThreadedListProcessor(ThreadedList<int> & p, mutex & resMutex, std::list<int> & res, int id) : m_p(p), m_resMutex(resMutex), m_res(res), m_id(id) { } @@ -37,52 +35,23 @@ struct ThreadedListProcessor : public threads::IRoutine } }; -struct ThreadedPriorityQueueProcessor : public threads::IRoutine -{ - ThreadedPriorityQueue<int> & m_p; - mutex & m_resMutex; - list<int> & m_res; - int m_id; - - ThreadedPriorityQueueProcessor(ThreadedPriorityQueue<int> & p, mutex & resMutex, list<int> & res, - int id) - : m_p(p), m_resMutex(resMutex), m_res(res), m_id(id) - { - } - - virtual void Do() - { - while (!m_p.IsCancelled()) - { - int res = m_p.Top(true /* doPop */); - { - lock_guard<mutex> resGuard(m_resMutex); - m_res.push_back(res); - } - LOG(LINFO, (m_id, " thread got ", res)); - threads::Sleep(10); - } - LOG(LINFO, (m_id, " thread is cancelled")); - } -}; - UNIT_TEST(ThreadedList) { - list<int> l; + std::list<int> l; mutex resMutex; - list<int> res; + std::list<int> res; ThreadedList<int> p; threads::Thread t0; - t0.Create(make_unique<ThreadedListProcessor>(p, resMutex, res, 0)); + t0.Create(my::make_unique<ThreadedListProcessor>(p, resMutex, res, 0)); threads::Thread t1; - t1.Create(make_unique<ThreadedListProcessor>(p, resMutex, res, 1)); + t1.Create(my::make_unique<ThreadedListProcessor>(p, resMutex, res, 1)); threads::Thread t2; - t2.Create(make_unique<ThreadedListProcessor>(p, resMutex, res, 2)); + t2.Create(my::make_unique<ThreadedListProcessor>(p, resMutex, res, 2)); p.PushBack(0); threads::Sleep(200); @@ -106,43 +75,3 @@ UNIT_TEST(ThreadedList) TEST_EQUAL(res.front(), 2, ()); res.pop_front(); } - -UNIT_TEST(ThreadedPriorityQueue) -{ - mutex resMutex; - list<int> res; - - ThreadedPriorityQueue<int> p; - - threads::Thread t0; - t0.Create(make_unique<ThreadedPriorityQueueProcessor>(p, resMutex, res, 0)); - - threads::Thread t1; - t1.Create(make_unique<ThreadedPriorityQueueProcessor>(p, resMutex, res, 1)); - - threads::Thread t2; - t2.Create(make_unique<ThreadedPriorityQueueProcessor>(p, resMutex, res, 2)); - - p.Push(0); - threads::Sleep(200); - - p.Push(1); - threads::Sleep(200); - - p.Push(2); - threads::Sleep(200); - - p.Cancel(); - - t0.Join(); - t1.Join(); - t2.Join(); - - TEST_EQUAL(res.front(), 0, ()); - res.pop_front(); - TEST_EQUAL(res.front(), 1, ()); - res.pop_front(); - TEST_EQUAL(res.front(), 2, ()); - res.pop_front(); -} - diff --git a/base/base_tests/threads_test.cpp b/base/base_tests/threads_test.cpp index 5f2af4bf29..e482cd55bb 100644 --- a/base/base_tests/threads_test.cpp +++ b/base/base_tests/threads_test.cpp @@ -1,8 +1,9 @@ #include "testing/testing.hpp" #include "base/thread.hpp" +#include "base/stl_add.hpp" -#include "std/vector.hpp" +#include <vector> typedef std::vector<int> Vector; @@ -44,13 +45,13 @@ UNIT_TEST(Simple_Threads) Vector vec; threads::Thread reader; - bool ok = reader.Create(make_unique<GeneratorThread>(vec)); + bool ok = reader.Create(my::make_unique<GeneratorThread>(vec)); TEST( ok, ("Create Generator thread") ); reader.Join(); threads::Thread writer; - ok = writer.Create(make_unique<ReaderThread>(vec)); + ok = writer.Create(my::make_unique<ReaderThread>(vec)); TEST( ok, ("Create Reader thread") ); writer.Join(); diff --git a/base/base_tests/worker_thread_test.cpp b/base/base_tests/worker_thread_test.cpp deleted file mode 100644 index a5f3ac456c..0000000000 --- a/base/base_tests/worker_thread_test.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "testing/testing.hpp" - -#include "base/worker_thread.hpp" - -#include "std/shared_ptr.hpp" -#include "std/vector.hpp" - -struct Task -{ - Task(vector<size_t> & buffer, size_t index) : m_buffer(buffer), m_index(index) {} - - void operator()() const { m_buffer.push_back(m_index); } - - vector<size_t> & m_buffer; - size_t m_index; -}; - -UNIT_TEST(WorkerThread_Basic) -{ - size_t const kNumTasks = 10; - size_t const kMaxTasksInQueue = 5; - - my::WorkerThread<Task> thread(kMaxTasksInQueue); - - vector<size_t> buffer; - for (size_t i = 0; i < kNumTasks; ++i) - thread.Push(make_shared<Task>(buffer, i)); - thread.RunUntilIdleAndStop(); - - TEST_EQUAL(kNumTasks, buffer.size(), ()); - for (size_t i = 0; i < buffer.size(); ++i) - TEST_EQUAL(i, buffer[i], ()); -} - -UNIT_TEST(WorkerThread_NoStopCall) -{ - size_t const kNumTasks = 10; - size_t const kMaxTasksInQueue = 5; - vector<size_t> buffer; - - { - my::WorkerThread<Task> thread(kMaxTasksInQueue); - for (size_t i = 0; i < kNumTasks; ++i) - thread.Push(make_shared<Task>(buffer, i)); - } - - TEST_EQUAL(kNumTasks, buffer.size(), ()); - for (size_t i = 0; i < buffer.size(); ++i) - TEST_EQUAL(i, buffer[i], ()); -} diff --git a/base/bits.hpp b/base/bits.hpp index 94c5d501db..f767c85d55 100644 --- a/base/bits.hpp +++ b/base/bits.hpp @@ -1,9 +1,9 @@ #pragma once #include "base/assert.hpp" -#include "std/cstdint.hpp" -#include "std/limits.hpp" -#include "std/type_traits.hpp" +#include <cstdint> +#include <limits> +#include <type_traits> namespace bits { @@ -112,16 +112,16 @@ namespace bits return (x << 1) | (x >> (sizeof(T) * 8 - 1)); } - template <typename T> inline typename make_unsigned<T>::type ZigZagEncode(T x) + template <typename T> inline typename std::make_unsigned<T>::type ZigZagEncode(T x) { - static_assert(is_signed<T>::value, "Type should be signed"); + static_assert(std::is_signed<T>::value, "Type should be signed"); return (x << 1) ^ (x >> (sizeof(x) * 8 - 1)); } - template <typename T> inline typename make_signed<T>::type ZigZagDecode(T x) + template <typename T> inline typename std::make_signed<T>::type ZigZagDecode(T x) { - static_assert(is_unsigned<T>::value, "Type should be unsigned."); - return (x >> 1) ^ -static_cast<typename make_signed<T>::type>(x & 1); + static_assert(std::is_unsigned<T>::value, "Type should be unsigned."); + return (x >> 1) ^ -static_cast<typename std::make_signed<T>::type>(x & 1); } inline uint32_t PerfectShuffle(uint32_t x) @@ -205,7 +205,7 @@ namespace bits inline uint64_t GetFullMask(uint8_t numBits) { ASSERT_LESS_OR_EQUAL(numBits, 64, ()); - return numBits == 64 ? numeric_limits<uint64_t>::max() + return numBits == 64 ? std::numeric_limits<uint64_t>::max() : (static_cast<uint64_t>(1) << numBits) - 1; } } // namespace bits diff --git a/base/buffer_vector.hpp b/base/buffer_vector.hpp index 646d41ef3e..f807cf18c7 100644 --- a/base/buffer_vector.hpp +++ b/base/buffer_vector.hpp @@ -1,13 +1,12 @@ #pragma once #include "base/assert.hpp" #include "base/stl_iterator.hpp" -#include "base/swap.hpp" -#include "std/algorithm.hpp" -#include "std/cstring.hpp" // for memcpy -#include "std/type_traits.hpp" -#include "std/utility.hpp" -#include "std/vector.hpp" +#include <algorithm> +#include <cstring> // for memcpy +#include <type_traits> +#include <utility> +#include <vector> template <class T, size_t N> class buffer_vector @@ -16,34 +15,34 @@ private: enum { USE_DYNAMIC = N + 1 }; T m_static[N]; size_t m_size; - vector<T> m_dynamic; + std::vector<T> m_dynamic; inline bool IsDynamic() const { return m_size == USE_DYNAMIC; } /// @todo clang on linux doesn't have is_trivially_copyable. #ifndef OMIM_OS_LINUX template <class U = T> - typename enable_if<is_trivially_copyable<U>::value, void>::type + typename std::enable_if<std::is_trivially_copyable<U>::value, void>::type MoveStatic(buffer_vector<T, N> & rhs) { memcpy(m_static, rhs.m_static, rhs.m_size*sizeof(T)); } template <class U = T> - typename enable_if<!is_trivially_copyable<U>::value, void>::type + typename std::enable_if<!std::is_trivially_copyable<U>::value, void>::type MoveStatic(buffer_vector<T, N> & rhs) { for (size_t i = 0; i < rhs.m_size; ++i) - Swap(m_static[i], rhs.m_static[i]); + std::swap(m_static[i], rhs.m_static[i]); } #else template <class U = T> - typename enable_if<is_pod<U>::value, void>::type + typename std::enable_if<std::is_pod<U>::value, void>::type MoveStatic(buffer_vector<T, N> & rhs) { memcpy(m_static, rhs.m_static, rhs.m_size*sizeof(T)); } template <class U = T> - typename enable_if<!is_pod<U>::value, void>::type + typename std::enable_if<!std::is_pod<U>::value, void>::type MoveStatic(buffer_vector<T, N> & rhs) { for (size_t i = 0; i < rhs.m_size; ++i) @@ -65,7 +64,7 @@ public: resize(n, c); } - explicit buffer_vector(initializer_list<T> const & initList) : m_size(0) + explicit buffer_vector(std::initializer_list<T> const & initList) : m_size(0) { assign(initList.begin(), initList.end()); } @@ -280,9 +279,9 @@ public: void swap(buffer_vector & rhs) { m_dynamic.swap(rhs.m_dynamic); - Swap(m_size, rhs.m_size); + std::swap(m_size, rhs.m_size); for (size_t i = 0; i < N; ++i) - Swap(m_static[i], rhs.m_static[i]); + std::swap(m_static[i], rhs.m_static[i]); } void push_back(T const & t) @@ -310,19 +309,19 @@ public: { if (IsDynamic()) { - m_dynamic.push_back(move(t)); + m_dynamic.push_back(std::move(t)); return; } if (m_size < N) { - Swap(m_static[m_size++], t); + std::swap(m_static[m_size++], t); } else { ASSERT_EQUAL(m_size, N, ()); SwitchToDynamic(); - m_dynamic.push_back(move(t)); + m_dynamic.push_back(std::move(t)); ASSERT_EQUAL(m_dynamic.size(), N + 1, ()); } } @@ -344,20 +343,20 @@ public: { if (IsDynamic()) { - m_dynamic.emplace_back(forward<Args>(args)...); + m_dynamic.emplace_back(std::forward<Args>(args)...); return; } if (m_size < N) { - value_type v(forward<Args>(args)...); - Swap(v, m_static[m_size++]); + value_type v(std::forward<Args>(args)...); + std::swap(v, m_static[m_size++]); } else { ASSERT_EQUAL(m_size, N, ()); SwitchToDynamic(); - m_dynamic.emplace_back(forward<Args>(args)...); + m_dynamic.emplace_back(std::forward<Args>(args)...); ASSERT_EQUAL(m_dynamic.size(), N + 1, ()); } } @@ -379,7 +378,7 @@ public: { if (pos != m_size) for (ptrdiff_t i = m_size - 1; i >= pos; --i) - Swap(m_static[i], m_static[i + n]); + std::swap(m_static[i], m_static[i + n]); m_size += n; T * writableWhere = &m_static[0] + pos; @@ -405,9 +404,9 @@ public: { iterator b = begin(); iterator e = end(); - iterator i = remove_if(b, e, fn); + iterator i = std::remove_if(b, e, fn); if (i != e) - resize(distance(b, i)); + resize(std::distance(b, i)); } private: @@ -419,7 +418,7 @@ private: for (size_t i = 0; i < m_size; ++i) { m_dynamic.emplace_back(); - Swap(m_static[i], m_dynamic.back()); + std::swap(m_static[i], m_dynamic.back()); } m_size = USE_DYNAMIC; } @@ -432,7 +431,7 @@ void swap(buffer_vector<T, N> & r1, buffer_vector<T, N> & r2) } template <typename T, size_t N> -inline string DebugPrint(buffer_vector<T, N> const & v) +inline std::string DebugPrint(buffer_vector<T, N> const & v) { return ::my::impl::DebugPrintSequence(v.data(), v.data() + v.size()); } @@ -452,5 +451,5 @@ inline bool operator!=(buffer_vector<T, N1> const & v1, buffer_vector<T, N2> con template <typename T, size_t N1, size_t N2> inline bool operator<(buffer_vector<T, N1> const & v1, buffer_vector<T, N2> const & v2) { - return lexicographical_compare(v1.begin(), v1.end(), v2.begin(), v2.end()); + return std::lexicographical_compare(v1.begin(), v1.end(), v2.begin(), v2.end()); } diff --git a/base/cache.hpp b/base/cache.hpp index eb695c9af7..9efa576f56 100644 --- a/base/cache.hpp +++ b/base/cache.hpp @@ -4,9 +4,9 @@ #include "base/base.hpp" #include "base/macros.hpp" -#include "std/type_traits.hpp" -#include "std/unique_ptr.hpp" -#include "std/utility.hpp" +#include <type_traits> +#include <memory> +#include <utility> namespace my @@ -29,7 +29,7 @@ namespace my void Init(uint32_t logCacheSize) { ASSERT(logCacheSize > 0 && logCacheSize < 32, (logCacheSize)); - static_assert((is_same<KeyT, uint32_t>::value || is_same<KeyT, uint64_t>::value), ""); + static_assert((std::is_same<KeyT, uint32_t>::value || std::is_same<KeyT, uint64_t>::value), ""); m_cache.reset(new Data[1 << logCacheSize]); m_hashMask = (1 << logCacheSize) - 1; @@ -106,7 +106,7 @@ namespace my ValueT m_Value; }; - unique_ptr<Data[]> m_cache; + std::unique_ptr<Data[]> m_cache; uint32_t m_hashMask; }; diff --git a/base/cancellable.hpp b/base/cancellable.hpp index 819272f3cb..4eb5787769 100644 --- a/base/cancellable.hpp +++ b/base/cancellable.hpp @@ -1,6 +1,6 @@ #pragma once -#include "std/atomic.hpp" +#include <atomic> namespace my { @@ -23,6 +23,6 @@ public: virtual bool IsCancelled() const { return m_cancelled; } private: - atomic<bool> m_cancelled; + std::atomic<bool> m_cancelled; }; } // namespace my diff --git a/base/condition.cpp b/base/condition.cpp index be9ecc000c..fd66f3b872 100644 --- a/base/condition.cpp +++ b/base/condition.cpp @@ -1,12 +1,90 @@ -#include "condition.hpp" +#include "base/condition.hpp" #include "std/target_os.hpp" -#if defined(OMIM_OS_WINDOWS_NATIVE) - #include "condition_windows_native.cpp" -#else - #include "condition_posix.cpp" -#endif +#include "base/mutex.hpp" +#include "std/systime.hpp" + +#include <pthread.h> + +#include <cstdint> +#include <cerrno> + + +namespace threads +{ + namespace impl + { + class ConditionImpl + { + public: + Mutex m_Mutex; + pthread_cond_t m_Condition; + }; + } + + Condition::Condition() : m_pImpl(new impl::ConditionImpl()) + { + ::pthread_cond_init(&m_pImpl->m_Condition, 0); + } + + Condition::~Condition() + { + ::pthread_cond_destroy(&m_pImpl->m_Condition); + delete m_pImpl; + } + + void Condition::Signal(bool broadcast) + { + if (broadcast) + ::pthread_cond_broadcast(&m_pImpl->m_Condition); + else + ::pthread_cond_signal(&m_pImpl->m_Condition); + } + + void Condition::Wait() + { + ::pthread_cond_wait(&m_pImpl->m_Condition, &m_pImpl->m_Mutex.m_Mutex); + } + + bool Condition::Wait(unsigned ms) + { + if (ms == -1) + { + Wait(); + return false; + } + + ::timeval curtv; + ::gettimeofday(&curtv, 0); + + ::timespec ts; + + uint64_t deltaNanoSec = curtv.tv_usec * 1000 + ms * 1000000; + + ts.tv_sec = curtv.tv_sec + deltaNanoSec / 1000000000; + ts.tv_nsec = deltaNanoSec % 1000000000; + + int res = ::pthread_cond_timedwait(&m_pImpl->m_Condition, &m_pImpl->m_Mutex.m_Mutex, &ts); + + return (res == ETIMEDOUT); + } + + void Condition::Lock() + { + m_pImpl->m_Mutex.Lock(); + } + + bool Condition::TryLock() + { + return m_pImpl->m_Mutex.TryLock(); + } + + void Condition::Unlock() + { + m_pImpl->m_Mutex.Unlock(); + } +} namespace threads { diff --git a/base/condition_bada.cpp b/base/condition_bada.cpp deleted file mode 100644 index 22ed384169..0000000000 --- a/base/condition_bada.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "std/target_os.hpp" - -#ifdef OMIM_OS_BADA - -#include "base/condition.hpp" - -#include <FBaseRtThreadMonitor.h> - -namespace threads -{ - namespace impl - { - class ConditionImpl - { - public: - Osp::Base::Runtime::Monitor m_Monitor; - }; - } - - Condition::Condition() : m_pImpl(new impl::ConditionImpl()) - { - m_pImpl->m_Monitor.Construct(); - } - - Condition::~Condition() - { - delete m_pImpl; - } - - void Condition::Signal(bool broadcast) - { - if (broadcast) - m_pImpl->m_Monitor.NotifyAll(); - else - m_pImpl->m_Monitor.Notify(); - } - - void Condition::Wait() - { - m_pImpl->m_Monitor.Wait(); - } - - void Condition::Lock() - { - m_pImpl->m_Monitor.Enter(); - } - - void Condition::Unlock() - { - m_pImpl->m_Monitor.Exit(); - } -} - -#endif // OMIM_OS_BADA diff --git a/base/condition_posix.cpp b/base/condition_posix.cpp deleted file mode 100644 index 24c743bbd4..0000000000 --- a/base/condition_posix.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include "std/target_os.hpp" - -#if !defined(OMIM_OS_WINDOWS_NATIVE) - -#include "base/condition.hpp" -#include "base/mutex.hpp" - -#include "std/cstdint.hpp" -#include "std/errno.hpp" -#include "std/systime.hpp" - -#include <pthread.h> - -namespace threads -{ - namespace impl - { - class ConditionImpl - { - public: - Mutex m_Mutex; - pthread_cond_t m_Condition; - }; - } - - Condition::Condition() : m_pImpl(new impl::ConditionImpl()) - { - ::pthread_cond_init(&m_pImpl->m_Condition, 0); - } - - Condition::~Condition() - { - ::pthread_cond_destroy(&m_pImpl->m_Condition); - delete m_pImpl; - } - - void Condition::Signal(bool broadcast) - { - if (broadcast) - ::pthread_cond_broadcast(&m_pImpl->m_Condition); - else - ::pthread_cond_signal(&m_pImpl->m_Condition); - } - - void Condition::Wait() - { - ::pthread_cond_wait(&m_pImpl->m_Condition, &m_pImpl->m_Mutex.m_Mutex); - } - - bool Condition::Wait(unsigned ms) - { - if (ms == -1) - { - Wait(); - return false; - } - - ::timeval curtv; - ::gettimeofday(&curtv, 0); - - ::timespec ts; - - uint64_t deltaNanoSec = curtv.tv_usec * 1000 + ms * 1000000; - - ts.tv_sec = curtv.tv_sec + deltaNanoSec / 1000000000; - ts.tv_nsec = deltaNanoSec % 1000000000; - - int res = ::pthread_cond_timedwait(&m_pImpl->m_Condition, &m_pImpl->m_Mutex.m_Mutex, &ts); - - return (res == ETIMEDOUT); - } - - void Condition::Lock() - { - m_pImpl->m_Mutex.Lock(); - } - - bool Condition::TryLock() - { - return m_pImpl->m_Mutex.TryLock(); - } - - void Condition::Unlock() - { - m_pImpl->m_Mutex.Unlock(); - } -} - -#endif diff --git a/base/condition_windows_native.cpp b/base/condition_windows_native.cpp deleted file mode 100644 index 3f6a69d7c3..0000000000 --- a/base/condition_windows_native.cpp +++ /dev/null @@ -1,291 +0,0 @@ -#include "std/target_os.hpp" - -#ifdef OMIM_OS_WINDOWS_NATIVE - -#include "base/condition.hpp" -#include "base/mutex.hpp" - -#include "std/windows.hpp" - -typedef void (WINAPI *InitFn)(PCONDITION_VARIABLE); -typedef void (WINAPI *WakeFn)(PCONDITION_VARIABLE); -typedef void (WINAPI *WakeAllFn)(PCONDITION_VARIABLE); -typedef BOOL (WINAPI *SleepFn)(PCONDITION_VARIABLE, PCRITICAL_SECTION, DWORD); - -namespace threads -{ - namespace impl - { - class ConditionImpl - { - public: - virtual ~ConditionImpl() {} - virtual void Signal(bool broadcast) = 0; - virtual void Wait() = 0; - virtual bool Wait(unsigned ms) = 0; - virtual void Lock() = 0; - virtual bool TryLock() = 0; - virtual void Unlock() = 0; - }; - - class ImplWinVista : public ConditionImpl - { - InitFn m_pInit; - WakeFn m_pWake; - WakeAllFn m_pWakeAll; - SleepFn m_pSleep; - - CONDITION_VARIABLE m_Condition; - Mutex m_mutex; - - public: - ImplWinVista(InitFn pInit, WakeFn pWake, WakeAllFn pWakeAll, SleepFn pSleep) - : m_pInit(pInit), m_pWake(pWake), m_pWakeAll(pWakeAll), m_pSleep(pSleep) - { - m_pInit(&m_Condition); - } - - void Signal(bool broadcast) - { - if (broadcast) - m_pWakeAll(&m_Condition); - else - m_pWake(&m_Condition); - } - - void Wait() - { - m_pSleep(&m_Condition, &m_mutex.m_Mutex, INFINITE); - } - - bool Wait(unsigned ms) - { - if (!m_pSleep(&m_Condition, &m_mutex.m_Mutex, ms)) - return GetLastError() == ERROR_TIMEOUT; - return false; - } - - void Lock() - { - m_mutex.Lock(); - } - - bool TryLock() - { - return m_mutex.TryLock(); - } - - void Unlock() - { - m_mutex.Unlock(); - } - }; - - /////////////////////////////////////////////////////////////// - /// Based on Richter's SignalObjectAndWait solution - class ImplWinXP : public ConditionImpl - { - /// Number of waiting threads - int waiters_count_; - /// Serialize access to <waiters_count_> - CRITICAL_SECTION waiters_count_lock_; - /// Semaphore used to queue up threads waiting for the condition to - /// become signaled - HANDLE sema_; - /// An auto-reset event used by the broadcast/signal thread to wait - /// for all the waiting thread(s) to wake up and be released from the - /// semaphore - HANDLE waiters_done_; - /// Keeps track of whether we were broadcasting or signaling. This - /// allows us to optimize the code if we're just signaling - size_t was_broadcast_; - - HANDLE m_mutex; - - public: - ImplWinXP() : waiters_count_(0), was_broadcast_(0) - { - ::InitializeCriticalSection(&waiters_count_lock_); - m_mutex = ::CreateMutexA(NULL, FALSE, NULL); - - sema_ = ::CreateSemaphore(NULL, // no security - 0, // initially 0 - 0x7fffffff, // max count - NULL); // unnamed - waiters_done_ = CreateEvent(NULL, // no security - FALSE, // auto-reset - FALSE, // non-signaled initially - NULL); // unnamed - } - - ~ImplWinXP() - { - ::CloseHandle(m_mutex); - ::DeleteCriticalSection(&waiters_count_lock_); - } - - void Signal(bool broadcast) - { - if (broadcast) - { - // This is needed to ensure that <waiters_count_> and <was_broadcast_> are - // consistent relative to each other - EnterCriticalSection(&waiters_count_lock_); - int have_waiters = 0; - - if (waiters_count_ > 0) - { - // We are broadcasting, even if there is just one waiter... - // Record that we are broadcasting, which helps optimize - // <pthread_cond_wait> for the non-broadcast case. - was_broadcast_ = 1; - have_waiters = 1; - } - - if (have_waiters) - { - // Wake up all the waiters atomically. - ReleaseSemaphore(sema_, waiters_count_, 0); - - LeaveCriticalSection(&waiters_count_lock_); - - // Wait for all the awakened threads to acquire the counting - // semaphore. - WaitForSingleObject(waiters_done_, INFINITE); - // This assignment is okay, wven without the <waiters_count_lock_> held - // because no other waiter threads can wake up to access it. - was_broadcast_ = 0; - } - else - LeaveCriticalSection(&waiters_count_lock_); - } - else - { - EnterCriticalSection(&waiters_count_lock_); - bool const have_waiters = waiters_count_ > 0; - LeaveCriticalSection(&waiters_count_lock_); - - // If there aren't any waiters, then this is a no-op. - if (have_waiters) - ::ReleaseSemaphore(sema_, 1, 0); - } - } - - void Wait() - { - Wait(-1); - } - - bool Wait(unsigned ms) - { - // Avoid race conditions - ::EnterCriticalSection(&waiters_count_lock_); - ++waiters_count_; - ::LeaveCriticalSection(&waiters_count_lock_); - - // This call atomically releases the mutex and waits on the - // semaphore until <pthread_cond_signal> or <pthread_cond_broadcast> - // are called by another thread - - DWORD toWait = (ms == -1) ? INFINITE : ms; - - bool res = false; - - if (::SignalObjectAndWait(m_mutex, sema_, toWait, FALSE) == WAIT_TIMEOUT) - res = true; - - // Reacquire lock to avoid race conditions - ::EnterCriticalSection(&waiters_count_lock_); - - // We're no longer waiting... - --waiters_count_; - - // Check to see if we're the last waiter after <pthread_cond_broadcast>. - bool const last_waiter = was_broadcast_ && waiters_count_ == 0; - - ::LeaveCriticalSection(&waiters_count_lock_); - - // If we're the last waiter thread during this particular broadcast - // then let all the other threads proceed - if (last_waiter) - // This call atomically signals the <waiters_done_> event and waits until - // it can acquire the <external_mutex>. This is required to ensure fairness. - ::SignalObjectAndWait(waiters_done_, m_mutex, INFINITE, FALSE); - else - // Always regain the external mutex since that's the guarantee we - // give to our callers. - ::WaitForSingleObject(m_mutex, INFINITE); - - return res; - } - - void Lock() - { - ::WaitForSingleObject(m_mutex, INFINITE); - } - - bool TryLock() - { - /// @todo I don't care :) - Lock(); - return true; - } - - void Unlock() - { - ::ReleaseMutex(m_mutex); - } - }; - } - /////////////////////////////////////////////////////////////// - Condition::Condition() - { - HMODULE handle = GetModuleHandle(TEXT("kernel32.dll")); - InitFn pInit = (InitFn)GetProcAddress(handle, "InitializeConditionVariable"); - WakeFn pWake = (WakeFn)GetProcAddress(handle, "WakeConditionVariable"); - WakeAllFn pWakeAll = (WakeFn)GetProcAddress(handle, "WakeAllConditionVariable"); - SleepFn pSleep = (SleepFn)GetProcAddress(handle, "SleepConditionVariableCS"); - - if (pInit && pWake && pWakeAll && pSleep) - m_pImpl = new impl::ImplWinVista(pInit, pWake, pWakeAll, pSleep); - else - m_pImpl = new impl::ImplWinXP(); - } - - Condition::~Condition() - { - delete m_pImpl; - } - - void Condition::Signal(bool broadcast) - { - m_pImpl->Signal(broadcast); - } - - void Condition::Wait() - { - return m_pImpl->Wait(); - } - - bool Condition::Wait(unsigned ms) - { - return m_pImpl->Wait(ms); - } - - void Condition::Lock() - { - m_pImpl->Lock(); - } - - bool Condition::TryLock() - { - return m_pImpl->TryLock(); - } - - void Condition::Unlock() - { - m_pImpl->Unlock(); - } -} - -#endif // OMIM_OS_WINDOWS_NATIVE diff --git a/base/const_helper.hpp b/base/const_helper.hpp deleted file mode 100644 index b5a71a9336..0000000000 --- a/base/const_helper.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -namespace my -{ - template <typename TFrom, typename TTo> struct PropagateConst - { - typedef TTo type; - }; - template <typename TFrom, typename TTo> struct PropagateConst<TFrom const, TTo> - { - typedef TTo const type; - }; -} diff --git a/base/deferred_task.cpp b/base/deferred_task.cpp index b6d76e0029..c3cc50e6ff 100644 --- a/base/deferred_task.cpp +++ b/base/deferred_task.cpp @@ -6,7 +6,7 @@ DeferredTask::DeferredTask(TDuration const & duration) : m_duration(duration) { m_thread = threads::SimpleThread([this] { - unique_lock<mutex> l(m_mutex); + std::unique_lock<std::mutex> l(m_mutex); while (!m_terminate) { if (!m_fn) @@ -15,7 +15,7 @@ DeferredTask::DeferredTask(TDuration const & duration) : m_duration(duration) continue; } - if (m_cv.wait_for(l, m_duration) != cv_status::timeout || !m_fn) + if (m_cv.wait_for(l, m_duration) != std::cv_status::timeout || !m_fn) continue; auto fn = move(m_fn); @@ -31,7 +31,7 @@ DeferredTask::DeferredTask(TDuration const & duration) : m_duration(duration) DeferredTask::~DeferredTask() { { - unique_lock<mutex> l(m_mutex); + std::unique_lock<std::mutex> l(m_mutex); m_terminate = true; } m_cv.notify_one(); @@ -41,7 +41,7 @@ DeferredTask::~DeferredTask() void DeferredTask::Drop() { { - unique_lock<mutex> l(m_mutex); + std::unique_lock<std::mutex> l(m_mutex); m_fn = nullptr; } m_cv.notify_one(); diff --git a/base/deferred_task.hpp b/base/deferred_task.hpp index de9b9e40cc..246b99d554 100644 --- a/base/deferred_task.hpp +++ b/base/deferred_task.hpp @@ -2,20 +2,20 @@ #include "base/thread.hpp" -#include "std/chrono.hpp" -#include "std/condition_variable.hpp" -#include "std/function.hpp" -#include "std/mutex.hpp" +#include <chrono> +#include <condition_variable> +#include <functional> +#include <mutex> namespace my { class DeferredTask { - using TDuration = duration<double>; + using TDuration = std::chrono::duration<double>; threads::SimpleThread m_thread; - mutex m_mutex; - condition_variable m_cv; - function<void()> m_fn; + std::mutex m_mutex; + std::condition_variable m_cv; + std::function<void()> m_fn; TDuration m_duration; bool m_terminate = false; @@ -29,7 +29,7 @@ public: void RestartWith(TFn const && fn) { { - unique_lock<mutex> l(m_mutex); + std::unique_lock<std::mutex> l(m_mutex); m_fn = fn; } m_cv.notify_one(); diff --git a/base/dfa_helpers.hpp b/base/dfa_helpers.hpp index 5815f380f9..3c04cbcd27 100644 --- a/base/dfa_helpers.hpp +++ b/base/dfa_helpers.hpp @@ -2,7 +2,7 @@ #include "base/string_utils.hpp" -#include "std/string.hpp" +#include <string> namespace strings { @@ -59,7 +59,7 @@ void DFAMove(DFAIt & it, UniString const & s) } template <typename DFAIt> -void DFAMove(DFAIt & it, string const & s) +void DFAMove(DFAIt & it, std::string const & s) { DFAMove(it, MakeUniString(s)); } diff --git a/base/exception.cpp b/base/exception.cpp index 78853d0150..4f8584a2c1 100644 --- a/base/exception.cpp +++ b/base/exception.cpp @@ -4,7 +4,7 @@ char const * RootException::what() const throw() { size_t const count = m_Msg.size(); - string asciiMsg; + std::string asciiMsg; asciiMsg.resize(count); for (size_t i = 0; i < count; ++i) @@ -15,7 +15,7 @@ char const * RootException::what() const throw() asciiMsg[i] = '?'; } - static string msg; - msg = string(m_What) + ", \"" + asciiMsg + "\""; + static std::string msg; + msg = std::string(m_What) + ", \"" + asciiMsg + "\""; return msg.c_str(); } diff --git a/base/exception.hpp b/base/exception.hpp index 195ff101ee..87be96775e 100644 --- a/base/exception.hpp +++ b/base/exception.hpp @@ -2,13 +2,13 @@ #include "base/internal/message.hpp" #include "base/macros.hpp" -#include "std/exception.hpp" -#include "std/string.hpp" +#include <exception> +#include <string> -class RootException : public exception +class RootException : public std::exception { public: - RootException(char const * what, string const & msg) : m_What(what), m_Msg(msg) + RootException(char const * what, std::string const & msg) : m_What(what), m_Msg(msg) { } @@ -18,14 +18,14 @@ public: virtual char const * what() const throw(); - string const & Msg() const throw() + std::string const & Msg() const throw() { return m_Msg; } private: char const * m_What; - string m_Msg; + std::string m_Msg; }; #define DECLARE_EXCEPTION(exception_name, base_exception) \ diff --git a/base/gmtime.hpp b/base/gmtime.hpp index c67e9f7ab8..a9552836b8 100644 --- a/base/gmtime.hpp +++ b/base/gmtime.hpp @@ -1,6 +1,6 @@ #pragma once -#include "std/ctime.hpp" +#include <ctime> namespace my { diff --git a/base/internal/message.cpp b/base/internal/message.cpp index 5c9804c8e2..8a17c6bb13 100644 --- a/base/internal/message.cpp +++ b/base/internal/message.cpp @@ -3,7 +3,7 @@ #include "std/target_os.hpp" -string DebugPrint(string const & t) +std::string DebugPrint(std::string const & t) { #ifdef OMIM_OS_WINDOWS string res; diff --git a/base/internal/message.hpp b/base/internal/message.hpp index f9775a9a15..03d6d0f957 100644 --- a/base/internal/message.hpp +++ b/base/internal/message.hpp @@ -1,71 +1,71 @@ #pragma once -#include "std/array.hpp" -#include "std/deque.hpp" -#include "std/functional.hpp" -#include "std/initializer_list.hpp" -#include "std/iterator.hpp" -#include "std/list.hpp" -#include "std/map.hpp" -#include "std/set.hpp" -#include "std/sstream.hpp" -#include "std/string.hpp" -#include "std/unique_ptr.hpp" -#include "std/unordered_map.hpp" -#include "std/unordered_set.hpp" -#include "std/utility.hpp" -#include "std/vector.hpp" +#include <array> +#include <deque> +#include <functional> +#include <initializer_list> +#include <iterator> +#include <list> +#include <map> +#include <set> +#include <sstream> +#include <string> +#include <memory> +#include <unordered_map> +#include <unordered_set> +#include <utility> +#include <vector> /// @name Declarations. //@{ -template <typename T> inline string DebugPrint(T const & t); - -string DebugPrint(string const & t); -inline string DebugPrint(char const * t); -inline string DebugPrint(char t); - -template <typename U, typename V> inline string DebugPrint(pair<U, V> const & p); -template <typename T> inline string DebugPrint(list<T> const & v); -template <typename T> inline string DebugPrint(vector<T> const & v); -template <typename T, typename C = less<T>> inline string DebugPrint(set<T, C> const & v); -template <typename T, typename C = less<T>> inline string DebugPrint(multiset<T, C> const & v); -template <typename U, typename V, typename C = less<U>> inline string DebugPrint(map<U, V, C> const & v); -template <typename T> inline string DebugPrint(initializer_list<T> const & v); -template <typename T> inline string DebugPrint(unique_ptr<T> const & v); - -template <class Key, class Hash = hash<Key>, class Pred = equal_to<Key>> -inline string DebugPrint(unordered_set<Key, Hash, Pred> const & v); -template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>> -inline string DebugPrint(unordered_map<Key, T, Hash, Pred> const & v); +template <typename T> inline std::string DebugPrint(T const & t); + +std::string DebugPrint(std::string const & t); +inline std::string DebugPrint(char const * t); +inline std::string DebugPrint(char t); + +template <typename U, typename V> inline std::string DebugPrint(std::pair<U, V> const & p); +template <typename T> inline std::string DebugPrint(std::list<T> const & v); +template <typename T> inline std::string DebugPrint(std::vector<T> const & v); +template <typename T, typename C = std::less<T>> inline std::string DebugPrint(std::set<T, C> const & v); +template <typename T, typename C = std::less<T>> inline std::string DebugPrint(std::multiset<T, C> const & v); +template <typename U, typename V, typename C = std::less<U>> inline std::string DebugPrint(std::map<U, V, C> const & v); +template <typename T> inline std::string DebugPrint(std::initializer_list<T> const & v); +template <typename T> inline std::string DebugPrint(std::unique_ptr<T> const & v); + +template <class Key, class Hash = std::hash<Key>, class Pred = std::equal_to<Key>> +inline std::string DebugPrint(std::unordered_set<Key, Hash, Pred> const & v); +template <class Key, class T, class Hash = std::hash<Key>, class Pred = std::equal_to<Key>> +inline std::string DebugPrint(std::unordered_map<Key, T, Hash, Pred> const & v); //@} -inline string DebugPrint(char const * t) +inline std::string DebugPrint(char const * t) { if (t) - return DebugPrint(string(t)); + return DebugPrint(std::string(t)); else - return string("NULL string pointer"); + return std::string("NULL string pointer"); } -inline string DebugPrint(char t) +inline std::string DebugPrint(char t) { - return DebugPrint(string(1, t)); + return DebugPrint(std::string(1, t)); } -inline string DebugPrint(signed char t) +inline std::string DebugPrint(signed char t) { return DebugPrint(static_cast<int>(t)); } -inline string DebugPrint(unsigned char t) +inline std::string DebugPrint(unsigned char t) { return DebugPrint(static_cast<unsigned int>(t)); } -template <typename U, typename V> inline string DebugPrint(pair<U,V> const & p) +template <typename U, typename V> inline std::string DebugPrint(std::pair<U,V> const & p) { - ostringstream out; + std::ostringstream out; out << "(" << DebugPrint(p.first) << ", " << DebugPrint(p.second) << ")"; return out.str(); } @@ -74,10 +74,10 @@ namespace my { namespace impl { - template <typename IterT> inline string DebugPrintSequence(IterT beg, IterT end) + template <typename IterT> inline std::string DebugPrintSequence(IterT beg, IterT end) { - ostringstream out; - out << "[" << distance(beg, end) << ":"; + std::ostringstream out; + out << "[" << std::distance(beg, end) << ":"; for (; beg != end; ++beg) out << " " << DebugPrint(*beg); out << " ]"; @@ -86,73 +86,73 @@ namespace my } } -template <typename T, size_t N> inline string DebugPrint(T (&arr) [N]) +template <typename T, size_t N> inline std::string DebugPrint(T (&arr) [N]) { return ::my::impl::DebugPrintSequence(arr, arr + N); } -template <typename T, size_t N> inline string DebugPrint(array<T, N> const & v) +template <typename T, size_t N> inline std::string DebugPrint(std::array<T, N> const & v) { return ::my::impl::DebugPrintSequence(v.begin(), v.end()); } -template <typename T> inline string DebugPrint(vector<T> const & v) +template <typename T> inline std::string DebugPrint(std::vector<T> const & v) { return ::my::impl::DebugPrintSequence(v.begin(), v.end()); } -template <typename T> inline string DebugPrint(deque<T> const & d) +template <typename T> inline std::string DebugPrint(std::deque<T> const & d) { return ::my::impl::DebugPrintSequence(d.begin(), d.end()); } -template <typename T> inline string DebugPrint(list<T> const & v) +template <typename T> inline std::string DebugPrint(std::list<T> const & v) { return ::my::impl::DebugPrintSequence(v.begin(), v.end()); } -template <typename T, typename C> inline string DebugPrint(set<T, C> const & v) +template <typename T, typename C> inline std::string DebugPrint(std::set<T, C> const & v) { return ::my::impl::DebugPrintSequence(v.begin(), v.end()); } -template <typename T, typename C> inline string DebugPrint(multiset<T, C> const & v) +template <typename T, typename C> inline std::string DebugPrint(std::multiset<T, C> const & v) { return ::my::impl::DebugPrintSequence(v.begin(), v.end()); } -template <typename U, typename V, typename C> inline string DebugPrint(map<U, V, C> const & v) +template <typename U, typename V, typename C> inline std::string DebugPrint(std::map<U, V, C> const & v) { return ::my::impl::DebugPrintSequence(v.begin(), v.end()); } -template <typename T> inline string DebugPrint(initializer_list<T> const & v) +template <typename T> inline std::string DebugPrint(std::initializer_list<T> const & v) { return ::my::impl::DebugPrintSequence(v.begin(), v.end()); } template <class Key, class Hash, class Pred> -inline string DebugPrint(unordered_set<Key, Hash, Pred> const & v) +inline std::string DebugPrint(std::unordered_set<Key, Hash, Pred> const & v) { return ::my::impl::DebugPrintSequence(v.begin(), v.end()); } template <class Key, class T, class Hash, class Pred> -inline string DebugPrint(unordered_map<Key, T, Hash, Pred> const & v) +inline std::string DebugPrint(std::unordered_map<Key, T, Hash, Pred> const & v) { return ::my::impl::DebugPrintSequence(v.begin(), v.end()); } -template <typename T> inline string DebugPrint(T const & t) +template <typename T> inline std::string DebugPrint(T const & t) { - ostringstream out; + std::ostringstream out; out << t; return out.str(); } -template <typename T> inline string DebugPrint(unique_ptr<T> const & v) +template <typename T> inline std::string DebugPrint(std::unique_ptr<T> const & v) { - ostringstream out; + std::ostringstream out; if (v.get() != nullptr) out << DebugPrint(*v); else @@ -164,15 +164,15 @@ namespace my { namespace impl { - inline string Message() + inline std::string Message() { - return string(); + return std::string(); } - template <typename T> string Message(T const & t) + template <typename T> std::string Message(T const & t) { return DebugPrint(t); } - template <typename T, typename... ARGS> string Message(T const & t, ARGS const & ... others) + template <typename T, typename... ARGS> std::string Message(T const & t, ARGS const & ... others) { return DebugPrint(t) + " " + Message(others...); } diff --git a/base/levenshtein_dfa.cpp b/base/levenshtein_dfa.cpp index 0586e83390..53912830c4 100644 --- a/base/levenshtein_dfa.cpp +++ b/base/levenshtein_dfa.cpp @@ -3,11 +3,11 @@ #include "base/assert.hpp" #include "base/stl_helpers.hpp" -#include "std/algorithm.hpp" -#include "std/queue.hpp" -#include "std/set.hpp" -#include "std/sstream.hpp" -#include "std/vector.hpp" +#include <algorithm> +#include <queue> +#include <set> +#include <sstream> +#include <vector> namespace strings { @@ -78,7 +78,7 @@ private: bool FindRelevant(LevenshteinDFA::Position const & p, UniChar c, size_t & i) const { size_t const limit = - min(m_size - p.m_offset, static_cast<size_t>(p.m_errorsLeft) + 1); + std::min(m_size - p.m_offset, static_cast<size_t>(p.m_errorsLeft) + 1); for (i = 0; i < limit; ++i) { @@ -152,7 +152,7 @@ void LevenshteinDFA::State::Normalize() { ASSERT_GREATER(j, 0, ()); --j; - swap(m_positions[i], m_positions[j]); + std::swap(m_positions[i], m_positions[j]); } } @@ -176,8 +176,8 @@ LevenshteinDFA::LevenshteinDFA(UniString const & s, size_t prefixCharsToKeep, ui } m_alphabet.push_back(missed); - queue<State> states; - map<State, size_t> visited; + std::queue<State> states; + std::map<State, size_t> visited; auto pushState = [&states, &visited, this](State const & state, size_t id) { @@ -231,7 +231,7 @@ LevenshteinDFA::LevenshteinDFA(UniString const & s, size_t prefixCharsToKeep, ui } } -LevenshteinDFA::LevenshteinDFA(string const & s, size_t prefixCharsToKeep, uint8_t maxErrors) +LevenshteinDFA::LevenshteinDFA(std::string const & s, size_t prefixCharsToKeep, uint8_t maxErrors) : LevenshteinDFA(MakeUniString(s), prefixCharsToKeep, maxErrors) { } @@ -241,7 +241,7 @@ LevenshteinDFA::LevenshteinDFA(UniString const & s, uint8_t maxErrors) { } -LevenshteinDFA::LevenshteinDFA(string const & s, uint8_t maxErrors) +LevenshteinDFA::LevenshteinDFA(std::string const & s, uint8_t maxErrors) : LevenshteinDFA(s, 0 /* prefixCharsToKeep */, maxErrors) { } @@ -304,17 +304,17 @@ size_t LevenshteinDFA::Move(size_t s, UniChar c) const return m_transitions[s][i]; } -string DebugPrint(LevenshteinDFA::Position const & p) +std::string DebugPrint(LevenshteinDFA::Position const & p) { - ostringstream os; + std::ostringstream os; os << "Position [" << p.m_offset << ", " << static_cast<uint32_t>(p.m_errorsLeft) << ", " << p.m_transposed << "]"; return os.str(); } -string DebugPrint(LevenshteinDFA::State const & s) +std::string DebugPrint(LevenshteinDFA::State const & s) { - ostringstream os; + std::ostringstream os; os << "State ["; for (size_t i = 0; i < s.m_positions.size(); ++i) { diff --git a/base/levenshtein_dfa.hpp b/base/levenshtein_dfa.hpp index 3ba7bbb22c..4edc06022c 100644 --- a/base/levenshtein_dfa.hpp +++ b/base/levenshtein_dfa.hpp @@ -2,8 +2,8 @@ #include "base/string_utils.hpp" -#include "std/cstdint.hpp" -#include "std/vector.hpp" +#include <cstdint> +#include <vector> namespace strings { @@ -61,7 +61,7 @@ public: inline bool operator<(State const & rhs) const { return m_positions < rhs.m_positions; } - vector<Position> m_positions; + std::vector<Position> m_positions; }; // An iterator to the current state in the DFA. @@ -90,9 +90,9 @@ public: }; LevenshteinDFA(UniString const & s, size_t prefixCharsToKeep, uint8_t maxErrors); - LevenshteinDFA(string const & s, size_t prefixCharsToKeep, uint8_t maxErrors); + LevenshteinDFA(std::string const & s, size_t prefixCharsToKeep, uint8_t maxErrors); LevenshteinDFA(UniString const & s, uint8_t maxErrors); - LevenshteinDFA(string const & s, uint8_t maxErrors); + LevenshteinDFA(std::string const & s, uint8_t maxErrors); inline Iterator Begin() const { return Iterator(*this); } @@ -120,12 +120,12 @@ private: size_t const m_size; uint8_t const m_maxErrors; - vector<UniChar> m_alphabet; + std::vector<UniChar> m_alphabet; - vector<vector<size_t>> m_transitions; - vector<bool> m_accepting; + std::vector<std::vector<size_t>> m_transitions; + std::vector<bool> m_accepting; }; -string DebugPrint(LevenshteinDFA::Position const & p); -string DebugPrint(LevenshteinDFA::State const & s); +std::string DebugPrint(LevenshteinDFA::Position const & p); +std::string DebugPrint(LevenshteinDFA::State const & s); } // namespace strings diff --git a/base/limited_priority_queue.hpp b/base/limited_priority_queue.hpp index 281108ef86..15bf294bf0 100644 --- a/base/limited_priority_queue.hpp +++ b/base/limited_priority_queue.hpp @@ -3,20 +3,20 @@ #include "base/base.hpp" #include "base/assert.hpp" -#include "std/algorithm.hpp" -#include "std/functional.hpp" -#include "std/vector.hpp" +#include <algorithm> +#include <functional> +#include <vector> namespace my { // Priority queue that stores only N smallest elements. -template <typename T, typename CompareT = less<T> > +template <typename T, typename CompareT = std::less<T> > class limited_priority_queue { public: typedef T value_type; - typedef typename vector<T>::const_iterator const_iterator; + typedef typename std::vector<T>::const_iterator const_iterator; explicit limited_priority_queue(size_t maxSize = 1, CompareT compare = CompareT()) : m_maxSize(maxSize == 0 ? 1 : maxSize), m_compare(compare) @@ -79,7 +79,7 @@ public: void reserve(size_t n) { m_queue.reserve(n); } private: - vector<T> m_queue; + std::vector<T> m_queue; size_t m_maxSize; CompareT m_compare; }; diff --git a/base/logging.cpp b/base/logging.cpp index 7af5d1b8ae..5e77051daa 100644 --- a/base/logging.cpp +++ b/base/logging.cpp @@ -5,12 +5,12 @@ #include "base/thread.hpp" #include "base/timer.hpp" -#include "std/iomanip.hpp" -#include "std/iostream.hpp" -#include "std/mutex.hpp" -#include "std/sstream.hpp" +#include <iomanip> +#include <iostream> +#include <mutex> +#include <sstream> #include "std/target_os.hpp" -#include "std/windows.hpp" +//#include "std/windows.hpp" namespace my @@ -18,7 +18,7 @@ namespace my class LogHelper { int m_threadsCount; - map<threads::ThreadID, int> m_threadID; + std::map<threads::ThreadID, int> m_threadID; int GetThreadID() { @@ -43,7 +43,7 @@ namespace my m_names[4] = "CRITICAL"; m_lens[4] = 8; } - void WriteProlog(ostream & s, LogLevel level) + void WriteProlog(std::ostream & s, LogLevel level) { s << "LOG"; @@ -51,33 +51,33 @@ namespace my s << " " << m_names[level]; double const sec = m_timer.ElapsedSeconds(); - s << " " << setfill(' ') << setw(static_cast<int>(16 - m_lens[level])) << sec << " "; + s << " " << std::setfill(' ') << std::setw(static_cast<int>(16 - m_lens[level])) << sec << " "; } }; - mutex g_logMutex; + std::mutex g_logMutex; - void LogMessageDefault(LogLevel level, SrcPoint const & srcPoint, string const & msg) + void LogMessageDefault(LogLevel level, SrcPoint const & srcPoint, std::string const & msg) { - lock_guard<mutex> lock(g_logMutex); + std::lock_guard<std::mutex> lock(g_logMutex); static LogHelper logger; - ostringstream out; + std::ostringstream out; logger.WriteProlog(out, level); - out << DebugPrint(srcPoint) << msg << endl; + out << DebugPrint(srcPoint) << msg << std::endl; std::cerr << out.str(); CHECK_LESS(level, g_LogAbortLevel, ("Abort. Log level is too serious", level)); } - void LogMessageTests(LogLevel level, SrcPoint const &, string const & msg) + void LogMessageTests(LogLevel level, SrcPoint const &, std::string const & msg) { - lock_guard<mutex> lock(g_logMutex); + std::lock_guard<std::mutex> lock(g_logMutex); - ostringstream out; - out << msg << endl; + std::ostringstream out; + out << msg << std::endl; std::cerr << out.str(); CHECK_LESS(level, g_LogAbortLevel, ("Abort. Log level is too serious", level)); diff --git a/base/logging.hpp b/base/logging.hpp index 657682d746..678a1b1685 100644 --- a/base/logging.hpp +++ b/base/logging.hpp @@ -4,7 +4,7 @@ #include "base/internal/message.hpp" #include "base/src_point.hpp" -#include "std/atomic.hpp" +#include <atomic> namespace my { @@ -17,8 +17,8 @@ namespace my LCRITICAL }; - typedef atomic<LogLevel> TLogLevel; - typedef void (*LogMessageFn)(LogLevel level, SrcPoint const &, string const &); + using TLogLevel = std::atomic<LogLevel>; + typedef void (*LogMessageFn)(LogLevel level, SrcPoint const &, std::string const &); extern LogMessageFn LogMessage; extern TLogLevel g_LogLevel; @@ -27,8 +27,8 @@ namespace my /// @return Pointer to previous message function. LogMessageFn SetLogMessageFn(LogMessageFn fn); - void LogMessageDefault(LogLevel level, SrcPoint const & srcPoint, string const & msg); - void LogMessageTests(LogLevel level, SrcPoint const & srcPoint, string const & msg); + void LogMessageDefault(LogLevel level, SrcPoint const & srcPoint, std::string const & msg); + void LogMessageTests(LogLevel level, SrcPoint const & srcPoint, std::string const & msg); /// Scope Guard to temporarily suppress specific log level, for example, in unit tests: /// ... diff --git a/base/math.hpp b/base/math.hpp index eb20ca4295..a213d6a2a3 100644 --- a/base/math.hpp +++ b/base/math.hpp @@ -1,11 +1,13 @@ #pragma once #include "base/assert.hpp" -#include "std/algorithm.hpp" #include "std/cmath.hpp" -#include "std/functional.hpp" -#include "std/limits.hpp" -#include "std/type_traits.hpp" + +#include <algorithm> +#include <cmath> +#include <functional> +#include <limits> +#include <type_traits> #include <boost/integer.hpp> @@ -27,8 +29,8 @@ template <typename T> inline T Abs(T x) template <typename TFloat> bool AlmostEqualULPs(TFloat x, TFloat y, unsigned int maxULPs = 256) { - static_assert(is_floating_point<TFloat>::value, ""); - static_assert(numeric_limits<TFloat>::is_iec559, ""); + static_assert(std::is_floating_point<TFloat>::value, ""); + static_assert(std::numeric_limits<TFloat>::is_iec559, ""); // Make sure maxUlps is non-negative and small enough that the // default NaN won't compare as equal to anything. @@ -70,7 +72,7 @@ inline bool AlmostEqualAbs(TFloat x, TFloat y, TFloat eps) template <typename TFloat> inline bool AlmostEqualRel(TFloat x, TFloat y, TFloat eps) { - return fabs(x - y) < eps * max(fabs(x), fabs(y)); + return fabs(x - y) < eps * std::max(fabs(x), fabs(y)); } // Returns true if x and y are equal up to the absolute or relative difference eps. @@ -187,7 +189,7 @@ template <typename T> T GCD(T a, T b) { if (a == 0 || b == 0) { - gcd = max(a, b); + gcd = std::max(a, b); break; } @@ -207,15 +209,15 @@ template <typename T> T GCD(T a, T b) if ((a & 0x1) != 0 && (b & 0x1) != 0) { - T const minV = min(a, b); - T const maxV = max(a, b); + T const minV = std::min(a, b); + T const maxV = std::max(a, b); a = (maxV - minV) >> 1; b = minV; continue; } if ((a & 0x1) != 0) - swap(a, b); + std::swap(a, b); a >>= 1; } @@ -228,7 +230,7 @@ template <typename T1, typename T2> size_t Hash(T1 const & t1, T2 const & t2) { /// @todo Probably, we need better hash for 2 integral types. - return (hash<T1>()(t1) ^ (hash<T2>()(t2) << 1)); + return (std::hash<T1>()(t1) ^ (std::hash<T2>()(t2) << 1)); } } diff --git a/base/matrix.hpp b/base/matrix.hpp index 9733bb99a5..63df382938 100644 --- a/base/matrix.hpp +++ b/base/matrix.hpp @@ -2,8 +2,8 @@ #include "base/math.hpp" -#include "std/iomanip.hpp" -#include "std/initializer_list.hpp" +#include <iomanip> +#include <initializer_list> namespace math @@ -27,10 +27,10 @@ namespace math copy(data, data + Rows * Cols, m_data); } - Matrix(initializer_list<T> const & initList) + Matrix(std::initializer_list<T> const & initList) { ASSERT(initList.size() == Rows * Cols, ()); - copy(initList.begin(), initList.end(), m_data); + std::copy(initList.begin(), initList.end(), m_data); } template <typename U> @@ -196,17 +196,17 @@ namespace math return res; } - template <typename T, unsigned M, unsigned N> string DebugPrint(Matrix<T, M, N> const & m) + template <typename T, unsigned M, unsigned N> std::string DebugPrint(Matrix<T, M, N> const & m) { - ostringstream ss; + std::ostringstream ss; - ss << ":" << endl; + ss << ":" << std::endl; for (unsigned i = 0; i < M; ++i) { for (unsigned j = 0; j < N; ++j) - ss << setfill(' ') << setw(10) << m(i, j) << " "; - ss << endl; + ss << std::setfill(' ') << std::setw(10) << m(i, j) << " "; + ss << std::endl; } return ss.str(); diff --git a/base/mem_trie.hpp b/base/mem_trie.hpp index 7c2a0eb7f2..46affa1cdc 100644 --- a/base/mem_trie.hpp +++ b/base/mem_trie.hpp @@ -2,8 +2,8 @@ #include "base/macros.hpp" -#include "std/map.hpp" -#include "std/vector.hpp" +#include <map> +#include <vector> namespace my { @@ -47,7 +47,7 @@ public: void ForEach(ToDo && toDo) { TString prefix; - ForEach(&m_root, prefix, forward<ToDo>(toDo)); + ForEach(&m_root, prefix, std::forward<ToDo>(toDo)); } template <typename ToDo> @@ -55,7 +55,7 @@ public: { Node const * node = MoveTo(prefix); if (node) - ForEach(node, prefix, forward<ToDo>(toDo)); + ForEach(node, prefix, std::forward<ToDo>(toDo)); } size_t GetNumNodes() const { return m_numNodes; } @@ -91,8 +91,8 @@ private: void AddValue(TValue const & value) { m_values.push_back(value); } - map<TChar, Node *> m_moves; - vector<TValue> m_values; + std::map<TChar, Node *> m_moves; + std::vector<TValue> m_values; DISALLOW_COPY(Node); }; diff --git a/base/newtype.hpp b/base/newtype.hpp index 5d435eda24..f9306c3ae7 100644 --- a/base/newtype.hpp +++ b/base/newtype.hpp @@ -1,21 +1,21 @@ #pragma once -#include "std/iostream.hpp" -#include "std/type_traits.hpp" +#include <iostream> +#include <type_traits> namespace my { namespace impl { template <typename From, typename To> -using IsConvertibleGuard = typename enable_if<is_convertible<From, To>::value>::type *; +using IsConvertibleGuard = typename std::enable_if<std::is_convertible<From, To>::value>::type *; } // namespace impl /// Creates a typesafe alias to a given numeric Type. template <typename Type, typename Tag> class NewType { - static_assert(is_integral<Type>::value || is_floating_point<Type>::value, + static_assert(std::is_integral<Type>::value || std::is_floating_point<Type>::value, "NewType can be used only with integral and floating point type."); public: diff --git a/base/object_tracker.cpp b/base/object_tracker.cpp deleted file mode 100644 index acad6d0a15..0000000000 --- a/base/object_tracker.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include "base/object_tracker.hpp" -#include "base/assert.hpp" -#include "base/logging.hpp" - -#include "std/target_os.hpp" - -#ifndef OMIM_OS_WINDOWS - #include <signal.h> - #include <unistd.h> -#else - #include "std/windows.hpp" -#endif - - -namespace dbg -{ - -map<void *, size_t> ObjectTracker::m_map; -size_t ObjectTracker::m_counter = 0; - -#ifdef TRACKER_MULTITHREADED -threads::Mutex ObjectTracker::m_mutex; -#endif - -void ObjectTracker::Add(void * p) -{ -#ifdef TRACKER_MULTITHREADED - threads::MutexGuard guard(m_mutex); -#endif - - CHECK ( m_map.insert(make_pair(p, m_counter++)).second == true, (p) ); -} - -void ObjectTracker::Remove(void * p) -{ -#ifdef TRACKER_MULTITHREADED - threads::MutexGuard guard(m_mutex); -#endif - - CHECK ( m_map.erase(p) == 1, (p) ); -} - -ObjectTracker::ObjectTracker() -{ - Add(this); -} - -ObjectTracker::ObjectTracker(ObjectTracker const &) -{ - Add(this); -} - -ObjectTracker::~ObjectTracker() -{ - Remove(this); -} - -void ObjectTracker::PrintLeaks() -{ -#ifdef TRACKER_MULTITHREADED - threads::MutexGuard guard(m_mutex); -#endif - - if (m_map.empty()) - LOG(LINFO, ("No leaks found!")); - else - LOG(LINFO, ("Leaks map:", m_map)); -} - -void BreakIntoDebugger() -{ - /// @todo Probably we can make it more simple (like std::terminate). - -#if defined(OMIM_OS_WINDOWS) - DebugBreak(); -#else - kill(getpid(), SIGINT); -#endif -} - -} diff --git a/base/object_tracker.hpp b/base/object_tracker.hpp deleted file mode 100644 index 377f511e96..0000000000 --- a/base/object_tracker.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include "base/base.hpp" -#include "base/mutex.hpp" - -#include "std/map.hpp" - - -#define TRACKER_MULTITHREADED - -namespace dbg -{ - class ObjectTracker - { - /// Pointer -> Info (Serial number of creation) - static map<void *, size_t> m_map; - static size_t m_counter; - -#ifdef TRACKER_MULTITHREADED - static threads::Mutex m_mutex; -#endif - - static void Add(void *); - static void Remove(void *); - - public: - ObjectTracker(); - ObjectTracker(ObjectTracker const & rhs); - ~ObjectTracker(); - - static void PrintLeaks(); - }; - - void BreakIntoDebugger(); -} diff --git a/base/observer_list.hpp b/base/observer_list.hpp index 04aab44b9b..0599a15ead 100644 --- a/base/observer_list.hpp +++ b/base/observer_list.hpp @@ -2,9 +2,9 @@ #include "base/logging.hpp" -#include "std/algorithm.hpp" -#include "std/mutex.hpp" -#include "std/vector.hpp" +#include <algorithm> +#include <mutex> +#include <vector> namespace my { @@ -16,7 +16,7 @@ class ObserverList public: bool Add(TObserver & observer) { - lock_guard<mutex> lock(m_observersLock); + std::lock_guard<std::mutex> lock(m_observersLock); auto const it = find(m_observers.begin(), m_observers.end(), &observer); if (it != m_observers.end()) { @@ -29,7 +29,7 @@ public: bool Remove(TObserver const & observer) { - lock_guard<mutex> lock(m_observersLock); + std::lock_guard<std::mutex> lock(m_observersLock); auto const it = find(m_observers.begin(), m_observers.end(), &observer); if (it == m_observers.end()) { @@ -43,13 +43,13 @@ public: template <typename F, typename... Args> void ForEach(F fn, Args const &... args) { - lock_guard<mutex> lock(m_observersLock); + std::lock_guard<std::mutex> lock(m_observersLock); for (TObserver * observer : m_observers) (observer->*fn)(args...); } private: - vector<TObserver *> m_observers; - mutex m_observersLock; + std::vector<TObserver *> m_observers; + std::mutex m_observersLock; }; } // namespace my diff --git a/base/range_iterator.hpp b/base/range_iterator.hpp index 7f2ee7ca3a..26e5270a98 100644 --- a/base/range_iterator.hpp +++ b/base/range_iterator.hpp @@ -1,7 +1,7 @@ #pragma once -#include "std/iterator.hpp" -#include "std/type_traits.hpp" +#include <iterator> +#include <type_traits> namespace my { diff --git a/base/ref_counted.hpp b/base/ref_counted.hpp index 54feffc08b..c63d388568 100644 --- a/base/ref_counted.hpp +++ b/base/ref_counted.hpp @@ -2,8 +2,8 @@ #include "base/macros.hpp" -#include "std/cstdint.hpp" -#include "std/unique_ptr.hpp" +#include <cstdint> +#include <memory> namespace my { @@ -36,15 +36,15 @@ public: m_p->IncRef(); } - explicit RefCountPtr(unique_ptr<T> p) noexcept : RefCountPtr(p.release()) {} + explicit RefCountPtr(std::unique_ptr<T> p) noexcept : RefCountPtr(p.release()) {} RefCountPtr(RefCountPtr const & rhs) { *this = rhs; } - RefCountPtr(RefCountPtr && rhs) { *this = move(rhs); } + RefCountPtr(RefCountPtr && rhs) { *this = std::move(rhs); } ~RefCountPtr() { Reset(); } - RefCountPtr & operator=(unique_ptr<T> p) + RefCountPtr & operator=(std::unique_ptr<T> p) { Reset(); diff --git a/base/set_operations.hpp b/base/set_operations.hpp index 4b28d93edf..a65a33629b 100644 --- a/base/set_operations.hpp +++ b/base/set_operations.hpp @@ -1,6 +1,6 @@ #pragma once -#include "std/algorithm.hpp" +#include <algorithm> // Similar to set_difference(), but if element is present n times in the first sequence and once in // the second sequence, all n copies are filtered, insted of one. @@ -29,5 +29,5 @@ OutIterT SetDifferenceUnlimited(Iter1T beg1, Iter1T end1, // ++beg2; } } - return copy(beg1, end1, out); + return std::copy(beg1, end1, out); } diff --git a/base/shared_buffer_manager.cpp b/base/shared_buffer_manager.cpp index 0e530e627f..1e5a33b085 100644 --- a/base/shared_buffer_manager.cpp +++ b/base/shared_buffer_manager.cpp @@ -20,7 +20,7 @@ SharedBufferManager::shared_buffer_ptr_t SharedBufferManager::reserveSharedBuffe shared_buffer_ptr_list_t & l = m_sharedBuffers[s]; if (l.empty()) - l.push_back(make_shared<shared_buffer_t>(s)); + l.push_back(std::make_shared<shared_buffer_t>(s)); shared_buffer_ptr_t res = l.front(); l.pop_front(); diff --git a/base/shared_buffer_manager.hpp b/base/shared_buffer_manager.hpp index c73b9d9215..42a6da9aa2 100644 --- a/base/shared_buffer_manager.hpp +++ b/base/shared_buffer_manager.hpp @@ -1,18 +1,19 @@ #pragma once #include "base/mutex.hpp" -#include "std/vector.hpp" -#include "std/shared_ptr.hpp" -#include "std/list.hpp" -#include "std/map.hpp" + +#include <vector> +#include <memory> +#include <list> +#include <map> class SharedBufferManager { public: - typedef vector<uint8_t> shared_buffer_t; - typedef shared_ptr<shared_buffer_t> shared_buffer_ptr_t; - typedef list<shared_buffer_ptr_t> shared_buffer_ptr_list_t; - typedef map<size_t, shared_buffer_ptr_list_t> shared_buffers_t; + typedef std::vector<uint8_t> shared_buffer_t; + typedef std::shared_ptr<shared_buffer_t> shared_buffer_ptr_t; + typedef std::list<shared_buffer_ptr_t> shared_buffer_ptr_list_t; + typedef std::map<size_t, shared_buffer_ptr_list_t> shared_buffers_t; private: threads::Mutex m_mutex; diff --git a/base/src_point.cpp b/base/src_point.cpp index 54b8976c18..663054f229 100644 --- a/base/src_point.cpp +++ b/base/src_point.cpp @@ -1,7 +1,7 @@ #include "base/src_point.hpp" -#include "std/algorithm.hpp" -#include "std/sstream.hpp" +#include <algorithm> +#include <sstream> namespace my @@ -15,7 +15,7 @@ void SrcPoint::TruncateFileName() { if (m_fileName[i] == '\\' || m_fileName[i] == '/') { - swap(p[0], p[1]); + std::swap(p[0], p[1]); p[0] = m_fileName + i + 1; } } @@ -24,9 +24,9 @@ void SrcPoint::TruncateFileName() } // namespace my -string DebugPrint(my::SrcPoint const & srcPoint) +std::string DebugPrint(my::SrcPoint const & srcPoint) { - ostringstream out; + std::ostringstream out; if (srcPoint.Line() > 0) out << srcPoint.FileName() << ":" << srcPoint.Line() << " " << srcPoint.Function() << srcPoint.Postfix() << " "; diff --git a/base/src_point.hpp b/base/src_point.hpp index d7552deba3..2d46d0af56 100644 --- a/base/src_point.hpp +++ b/base/src_point.hpp @@ -1,6 +1,6 @@ #pragma once -#include "std/string.hpp" +#include <string> #ifndef SRC_LOGGING @@ -63,4 +63,4 @@ namespace my }; } -string DebugPrint(my::SrcPoint const & srcPoint); +std::string DebugPrint(my::SrcPoint const & srcPoint); diff --git a/base/stats.hpp b/base/stats.hpp index 93982659f3..590c296ed4 100644 --- a/base/stats.hpp +++ b/base/stats.hpp @@ -1,8 +1,8 @@ #pragma once #include "base/base.hpp" -#include "std/sstream.hpp" -#include "std/string.hpp" +#include <sstream> +#include <string> namespace my @@ -13,7 +13,7 @@ template <typename T> class NoopStats public: NoopStats() {} inline void operator() (T const &) {} - inline string GetStatsStr() const { return ""; } + inline std::string GetStatsStr() const { return ""; } }; template <typename T> class AverageStats @@ -29,7 +29,7 @@ public: string GetStatsStr() const { - ostringstream out; + std::ostringstream out; out << "N: " << m_Count; if (m_Count > 0) out << " Av: " << m_Sum / m_Count; diff --git a/base/std_serialization.hpp b/base/std_serialization.hpp index b9767d8634..87dc188668 100644 --- a/base/std_serialization.hpp +++ b/base/std_serialization.hpp @@ -2,26 +2,26 @@ #include "base/base.hpp" -#include "std/map.hpp" -#include "std/set.hpp" -#include "std/unordered_map.hpp" -#include "std/vector.hpp" -#include "std/array.hpp" -#include "std/utility.hpp" +#include <array> +#include <map> +#include <set> +#include <unordered_map> +#include <utility> +#include <vector> /// @name std containers serialization /// TArchive should be an archive class in global namespace. //@{ template <class TArchive, class T1, class T2> -TArchive & operator << (TArchive & ar, pair<T1, T2> const & t) +TArchive & operator << (TArchive & ar, std::pair<T1, T2> const & t) { ar << t.first << t.second; return ar; } template <class TArchive, class T1, class T2> -TArchive & operator >> (TArchive & ar, pair<T1, T2> & t) +TArchive & operator >> (TArchive & ar, std::pair<T1, T2> & t) { ar >> t.first >> t.second; return ar; @@ -100,74 +100,74 @@ template <class TArchive, class TCont> void load_like_set(TArchive & ar, TCont & } } -template <class TArchive, class T1, class T2> TArchive & operator << (TArchive & ar, map<T1, T2> const & rMap) +template <class TArchive, class T1, class T2> TArchive & operator << (TArchive & ar, std::map<T1, T2> const & rMap) { save_like_map(ar, rMap); return ar; } -template <class TArchive, class T1, class T2> TArchive & operator >> (TArchive & ar, map<T1, T2> & rMap) +template <class TArchive, class T1, class T2> TArchive & operator >> (TArchive & ar, std::map<T1, T2> & rMap) { load_like_map(ar, rMap); return ar; } -template <class TArchive, class T1, class T2> TArchive & operator << (TArchive & ar, multimap<T1, T2> const & rMap) +template <class TArchive, class T1, class T2> TArchive & operator << (TArchive & ar, std::multimap<T1, T2> const & rMap) { save_like_map(ar, rMap); return ar; } -template <class TArchive, class T1, class T2> TArchive & operator >> (TArchive & ar, multimap<T1, T2> & rMap) +template <class TArchive, class T1, class T2> TArchive & operator >> (TArchive & ar, std::multimap<T1, T2> & rMap) { load_like_map(ar, rMap); return ar; } -template <class TArchive, class T1, class T2> TArchive & operator << (TArchive & ar, unordered_map<T1, T2> const & rMap) +template <class TArchive, class T1, class T2> TArchive & operator << (TArchive & ar, std::unordered_map<T1, T2> const & rMap) { save_like_map(ar, rMap); return ar; } -template <class TArchive, class T1, class T2> TArchive & operator >> (TArchive & ar, unordered_map<T1, T2> & rMap) +template <class TArchive, class T1, class T2> TArchive & operator >> (TArchive & ar, std::unordered_map<T1, T2> & rMap) { load_like_map(ar, rMap); return ar; } -template <class TArchive, class T> TArchive & operator << (TArchive & ar, vector<T> const & rVector) +template <class TArchive, class T> TArchive & operator << (TArchive & ar, std::vector<T> const & rVector) { save_like_vector(ar, rVector); return ar; } -template <class TArchive, class T> TArchive & operator >> (TArchive & ar, vector<T> & rVector) +template <class TArchive, class T> TArchive & operator >> (TArchive & ar, std::vector<T> & rVector) { load_like_vector(ar, rVector); return ar; } -template <class TArchive, class T> TArchive & operator << (TArchive & ar, set<T> const & rSet) +template <class TArchive, class T> TArchive & operator << (TArchive & ar, std::set<T> const & rSet) { save_like_set(ar, rSet); return ar; } -template <class TArchive, class T> TArchive & operator >> (TArchive & ar, set<T> & rSet) +template <class TArchive, class T> TArchive & operator >> (TArchive & ar, std::set<T> & rSet) { load_like_set(ar, rSet); return ar; } -template <class TArchive, class T, size_t N> TArchive & operator << (TArchive & ar, array<T, N> const & rArray) +template <class TArchive, class T, size_t N> TArchive & operator << (TArchive & ar, std::array<T, N> const & rArray) { for (size_t i = 0; i < N; ++i) ar << rArray[i]; return ar; } -template <class TArchive, class T, size_t N> TArchive & operator >> (TArchive & ar, array<T, N> & rArray) +template <class TArchive, class T, size_t N> TArchive & operator >> (TArchive & ar, std::array<T, N> & rArray) { for (size_t i = 0; i < N; ++i) ar >> rArray[i]; @@ -179,7 +179,7 @@ namespace serial { /// @name This functions invokes overriten do_load for type T with index in array. //@{ - template <class TArchive, class T> void do_load(TArchive & ar, size_t ind, vector<T> & rVector) + template <class TArchive, class T> void do_load(TArchive & ar, size_t ind, std::vector<T> & rVector) { uint32_t count; ar >> count; @@ -189,7 +189,7 @@ namespace serial do_load(ar, ind, rVector[i]); } - template <class TArchive, class T, size_t N> void do_load(TArchive & ar, array<T, N> & rArray) + template <class TArchive, class T, size_t N> void do_load(TArchive & ar, std::array<T, N> & rArray) { for (size_t i = 0; i < N; ++i) do_load(ar, i, rArray[i]); diff --git a/base/stl_add.hpp b/base/stl_add.hpp index 8ccfdffa53..d30c16d2b8 100644 --- a/base/stl_add.hpp +++ b/base/stl_add.hpp @@ -1,7 +1,19 @@ #pragma once -#include "std/functional.hpp" -#include "std/iterator.hpp" -#include "std/algorithm.hpp" + +#include <algorithm> +#include <functional> +#include <iterator> + +namespace my +{ +/// @todo(y): replace this hand-written helper function by +/// std::make_unique when it will be available in C++14 +template <typename T, typename... Args> +std::unique_ptr<T> make_unique(Args &&... args) +{ + return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); +} +} template <class ContainerT> class BackInsertFunctor @@ -80,7 +92,7 @@ IterT RemoveIfKeepValid(IterT beg, IterT end, CompareT comp) { if (!comp(*end)) { - swap(*beg, *end); + std::swap(*beg, *end); ++beg; break; } @@ -96,12 +108,12 @@ IterT RemoveIfKeepValid(IterT beg, IterT end, CompareT comp) template <class IterT> inline bool IsSorted(IterT beg, IterT end) { - return IsSorted(beg, end, less<typename iterator_traits<IterT>::value_type>()); + return IsSorted(beg, end, std::less<typename std::iterator_traits<IterT>::value_type>()); } template <class IterT> inline bool IsSortedAndUnique(IterT beg, IterT end) { - return IsSortedAndUnique(beg, end, less<typename iterator_traits<IterT>::value_type>()); + return IsSortedAndUnique(beg, end, std::less<typename std::iterator_traits<IterT>::value_type>()); } struct DeleteFunctor @@ -186,7 +198,7 @@ template <class IterT1, class IterT2, class InsertIterT> void AccumulateIntervals1With2(IterT1 b1, IterT1 e1, IterT2 b2, IterT2 e2, InsertIterT res) { //typedef typename iterator_traits<InsertIterT>::value_type T; - typedef typename iterator_traits<IterT1>::value_type T; + typedef typename std::iterator_traits<IterT1>::value_type T; T prev; bool validPrev = false; diff --git a/base/stl_helpers.hpp b/base/stl_helpers.hpp index 3a667766de..7f39e39a59 100644 --- a/base/stl_helpers.hpp +++ b/base/stl_helpers.hpp @@ -1,9 +1,9 @@ #pragma once -#include "std/algorithm.hpp" -#include "std/functional.hpp" -#include "std/utility.hpp" -#include "std/vector.hpp" +#include <algorithm> +#include <functional> +#include <utility> +#include <vector> namespace my { @@ -93,14 +93,14 @@ void SortUnique(Cont & c) template <class Cont, typename Less, typename Equals> void SortUnique(Cont & c, Less && less, Equals && equals) { - sort(c.begin(), c.end(), forward<Less>(less)); - c.erase(unique(c.begin(), c.end(), forward<Equals>(equals)), c.end()); + sort(c.begin(), c.end(), std::forward<Less>(less)); + c.erase(unique(c.begin(), c.end(), std::forward<Equals>(equals)), c.end()); } template <class Cont, class Fn> void EraseIf(Cont & c, Fn && fn) { - c.erase(remove_if(c.begin(), c.end(), forward<Fn>(fn)), c.end()); + c.erase(remove_if(c.begin(), c.end(), std::forward<Fn>(fn)), c.end()); } // Creates a comparer being able to compare two instances of class C diff --git a/base/stl_iterator.hpp b/base/stl_iterator.hpp index 153c6436fa..a409f08b5f 100644 --- a/base/stl_iterator.hpp +++ b/base/stl_iterator.hpp @@ -1,6 +1,6 @@ #pragma once -#include "std/iterator_facade.hpp" +#include <boost/iterator/iterator_facade.hpp> namespace detail { @@ -11,7 +11,7 @@ struct Dummy } class CounterIterator : - public iterator_facade<CounterIterator, detail::Dummy, forward_traversal_tag> + public boost::iterator_facade<CounterIterator, detail::Dummy, boost::forward_traversal_tag> { size_t m_count; public: diff --git a/base/string_format.cpp b/base/string_format.cpp index 86a7447743..7f4c7019a1 100644 --- a/base/string_format.cpp +++ b/base/string_format.cpp @@ -1,21 +1,21 @@ #include "base/string_format.hpp" -#include "std/list.hpp" +#include <list> namespace strings { - string const FormatImpl(string const & s, string arr[], size_t count) + std::string const FormatImpl(std::string const & s, std::string arr[], size_t count) { size_t offs = 0; - list<size_t> fieldOffs; + std::list<size_t> fieldOffs; - string res = s; + std::string res = s; while (true) { offs = res.find("^", offs); - if (offs == string::npos) + if (offs == std::string::npos) break; else { @@ -34,7 +34,7 @@ namespace strings offs = 0; size_t i = 0; - for (list<size_t>::const_iterator offsIt = fieldOffs.begin(); + for (std::list<size_t>::const_iterator offsIt = fieldOffs.begin(); (offsIt != fieldOffs.end()) && (i < count); ++offsIt, ++i) { diff --git a/base/string_format.hpp b/base/string_format.hpp index 05875cac48..a5186fcbaa 100644 --- a/base/string_format.hpp +++ b/base/string_format.hpp @@ -2,56 +2,56 @@ #include "base/base.hpp" #include "base/macros.hpp" -#include "std/string.hpp" -#include "std/sstream.hpp" +#include <string> +#include <sstream> namespace strings { template <typename T> - string ToString(T const & t) + std::string ToString(T const & t) { // May be we should use DebugPrint here. Not sure. - ostringstream out; + std::ostringstream out; out << t; return out.str(); } - string const FormatImpl(string const & s, string arr[], size_t count); + std::string const FormatImpl(std::string const & s, std::string arr[], size_t count); template <typename T1> - string const Format(string const & s, T1 const & t1) + std::string const Format(std::string const & s, T1 const & t1) { - string arr[] = { ToString(t1) }; + std::string arr[] = { ToString(t1) }; return FormatImpl(s, arr, ARRAY_SIZE(arr)); } template <typename T1, typename T2> - string const Format(string const & s, T1 const & t1, T2 const & t2) + std::string const Format(std::string const & s, T1 const & t1, T2 const & t2) { - string arr[] = { ToString(t1), ToString(t2) }; + std::string arr[] = { ToString(t1), ToString(t2) }; return FormatImpl(s, arr, ARRAY_SIZE(arr)); } template <typename T1, typename T2, typename T3> - string const Format(string const & s, T1 const & t1, T2 const & t2, T3 const & t3) + std::string const Format(std::string const & s, T1 const & t1, T2 const & t2, T3 const & t3) { - string arr[] = { ToString(t1), ToString(t2), ToString(t3) }; + std::string arr[] = { ToString(t1), ToString(t2), ToString(t3) }; return FormatImpl(s, arr, ARRAY_SIZE(arr)); } template <typename T1, typename T2, typename T3, typename T4> - string const Format(string const & s, T1 const & t1, T2 const & t2, T3 const & t3, T4 const & t4) + std::string const Format(std::string const & s, T1 const & t1, T2 const & t2, T3 const & t3, T4 const & t4) { - string arr[] = { ToString(t1), ToString(t2), ToString(t3), ToString(t4) }; + std::string arr[] = { ToString(t1), ToString(t2), ToString(t3), ToString(t4) }; return FormatImpl(s, arr, ARRAY_SIZE(arr)); } template <typename T1, typename T2, typename T3, typename T4, typename T5> - string const Format(string const & s, T1 const & t1, T2 const & t2, T3 const & t3, T4 const & t4, T5 const & t5) + std::string const Format(std::string const & s, T1 const & t1, T2 const & t2, T3 const & t3, T4 const & t4, T5 const & t5) { - string arr[] = { ToString(t1), ToString(t2), ToString(t3), ToString(t4), ToString(t5) }; + std::string arr[] = { ToString(t1), ToString(t2), ToString(t3), ToString(t4), ToString(t5) }; return FormatImpl(s, arr, ARRAY_SIZE(arr)); } } diff --git a/base/string_utils.cpp b/base/string_utils.cpp index 67eed2cb12..6379deab9e 100644 --- a/base/string_utils.cpp +++ b/base/string_utils.cpp @@ -1,25 +1,26 @@ #include "base/assert.hpp" #include "base/string_utils.hpp" -#include "std/algorithm.hpp" -#include "std/cmath.hpp" -#include "std/iomanip.hpp" -#include "std/iterator.hpp" #include "std/target_os.hpp" +#include <algorithm> +#include <cmath> +#include <iomanip> +#include <iterator> + #include <boost/algorithm/string/trim.hpp> namespace strings { bool UniString::IsEqualAscii(char const * s) const { - return (size() == strlen(s) && equal(begin(), end(), s)); + return (size() == strlen(s) && std::equal(begin(), end(), s)); } SimpleDelimiter::SimpleDelimiter(char const * delims) { - string const s(delims); - string::const_iterator it = s.begin(); + std::string const s(delims); + std::string::const_iterator it = s.begin(); while (it != s.end()) m_delims.push_back(utf8::unchecked::next(it)); } @@ -31,14 +32,14 @@ SimpleDelimiter::SimpleDelimiter(char delim) bool SimpleDelimiter::operator()(UniChar c) const { - return find(m_delims.begin(), m_delims.end(), c) != m_delims.end(); + return std::find(m_delims.begin(), m_delims.end(), c) != m_delims.end(); } -UniChar LastUniChar(string const & s) +UniChar LastUniChar(std::string const & s) { if (s.empty()) return 0; - utf8::unchecked::iterator<string::const_iterator> iter(s.end()); + utf8::unchecked::iterator<std::string::const_iterator> iter(s.end()); --iter; return *iter; } @@ -117,18 +118,18 @@ UniString MakeLowerCase(UniString const & s) return result; } -void MakeLowerCaseInplace(string & s) +void MakeLowerCaseInplace(std::string & s) { UniString uniStr; - utf8::unchecked::utf8to32(s.begin(), s.end(), back_inserter(uniStr)); + utf8::unchecked::utf8to32(s.begin(), s.end(), std::back_inserter(uniStr)); MakeLowerCaseInplace(uniStr); s.clear(); utf8::unchecked::utf32to8(uniStr.begin(), uniStr.end(), back_inserter(s)); } -string MakeLowerCase(string const & s) +std::string MakeLowerCase(std::string const & s) { - string result(s); + std::string result(s); MakeLowerCaseInplace(result); return result; } @@ -140,7 +141,7 @@ UniString Normalize(UniString const & s) return result; } -void NormalizeDigits(string & utf8) +void NormalizeDigits(std::string & utf8) { size_t const n = utf8.size(); size_t const m = n >= 2 ? n - 2 : 0; @@ -204,29 +205,29 @@ char ascii_to_lower(char in) } } -void AsciiToLower(string & s) { transform(s.begin(), s.end(), s.begin(), &ascii_to_lower); } -void Trim(string & s) { boost::trim(s); } -void Trim(string & s, char const * anyOf) { boost::trim_if(s, boost::is_any_of(anyOf)); } -bool EqualNoCase(string const & s1, string const & s2) +void AsciiToLower(std::string & s) { transform(s.begin(), s.end(), s.begin(), &ascii_to_lower); } +void Trim(std::string & s) { boost::trim(s); } +void Trim(std::string & s, char const * anyOf) { boost::trim_if(s, boost::is_any_of(anyOf)); } +bool EqualNoCase(std::string const & s1, std::string const & s2) { return MakeLowerCase(s1) == MakeLowerCase(s2); } -UniString MakeUniString(string const & utf8s) +UniString MakeUniString(std::string const & utf8s) { UniString result; - utf8::unchecked::utf8to32(utf8s.begin(), utf8s.end(), back_inserter(result)); + utf8::unchecked::utf8to32(utf8s.begin(), utf8s.end(), std::back_inserter(result)); return result; } -string ToUtf8(UniString const & s) +std::string ToUtf8(UniString const & s) { - string result; + std::string result; utf8::unchecked::utf32to8(s.begin(), s.end(), back_inserter(result)); return result; } -bool IsASCIIString(string const & str) +bool IsASCIIString(std::string const & str) { for (size_t i = 0; i < str.size(); ++i) if (str[i] & 0x80) @@ -248,8 +249,8 @@ bool StartsWith(UniString const & s, UniString const & p) return true; } -bool StartsWith(string const & s1, char const * s2) { return (s1.compare(0, strlen(s2), s2) == 0); } -bool EndsWith(string const & s1, char const * s2) +bool StartsWith(std::string const & s1, char const * s2) { return (s1.compare(0, strlen(s2), s2) == 0); } +bool EndsWith(std::string const & s1, char const * s2) { size_t const n = s1.size(); size_t const m = strlen(s2); @@ -258,29 +259,29 @@ bool EndsWith(string const & s1, char const * s2) return (s1.compare(n - m, m, s2) == 0); } -bool EndsWith(string const & s1, string const & s2) +bool EndsWith(std::string const & s1, std::string const & s2) { return s1.size() >= s2.size() && s1.compare(s1.size() - s2.size(), s2.size(), s2) == 0; } -string to_string_dac(double d, int dac) +std::string to_string_dac(double d, int dac) { - dac = min(numeric_limits<double>::digits10, dac); + dac = std::min(std::numeric_limits<double>::digits10, dac); - ostringstream ss; + std::ostringstream ss; if (d < 1. && d > -1.) { - string res; + std::string res; if (d >= 0.) { - ss << setprecision(dac + 1) << d + 1; + ss << std::setprecision(dac + 1) << d + 1; res = ss.str(); res[0] = '0'; } else { - ss << setprecision(dac + 1) << d - 1; + ss << std::setprecision(dac + 1) << d - 1; res = ss.str(); res[1] = '0'; } @@ -289,19 +290,19 @@ string to_string_dac(double d, int dac) // Calc digits before comma (log10). double fD = fabs(d); - while (fD >= 1.0 && dac < numeric_limits<double>::digits10) + while (fD >= 1.0 && dac < std::numeric_limits<double>::digits10) { fD /= 10.0; ++dac; } - ss << setprecision(dac) << d; + ss << std::setprecision(dac) << d; return ss.str(); } -bool IsHTML(string const & utf8) +bool IsHTML(std::string const & utf8) { - string::const_iterator it = utf8.begin(); + std::string::const_iterator it = utf8.begin(); size_t ltCount = 0; size_t gtCount = 0; while (it != utf8.end()) @@ -315,15 +316,15 @@ bool IsHTML(string const & utf8) return (ltCount > 0 && gtCount > 0); } -bool AlmostEqual(string const & str1, string const & str2, size_t mismatchedCount) +bool AlmostEqual(std::string const & str1, std::string const & str2, size_t mismatchedCount) { - pair<string::const_iterator, string::const_iterator> mis(str1.begin(), str2.begin()); + std::pair<std::string::const_iterator, std::string::const_iterator> mis(str1.begin(), str2.begin()); auto const str1End = str1.end(); auto const str2End = str2.end(); for (size_t i = 0; i <= mismatchedCount; ++i) { - auto const end = mis.first + min(distance(mis.first, str1End), distance(mis.second, str2End)); + auto const end = mis.first + std::min(distance(mis.first, str1End), distance(mis.second, str2End)); mis = mismatch(mis.first, end, mis.second); if (mis.first == str1End && mis.second == str2End) return true; @@ -335,13 +336,13 @@ bool AlmostEqual(string const & str1, string const & str2, size_t mismatchedCoun return false; } -void ParseCSVRow(string const & s, char const delimiter, vector<string> & target) +void ParseCSVRow(std::string const & s, char const delimiter, std::vector<std::string> & target) { target.clear(); - using It = TokenizeIterator<SimpleDelimiter, string::const_iterator, true>; + using It = TokenizeIterator<SimpleDelimiter, std::string::const_iterator, true>; for (It it(s, SimpleDelimiter(delimiter)); it; ++it) { - string column = *it; + std::string column = *it; strings::Trim(column); target.push_back(move(column)); } diff --git a/base/string_utils.hpp b/base/string_utils.hpp index 8a9c925ef4..af8670c5a4 100644 --- a/base/string_utils.hpp +++ b/base/string_utils.hpp @@ -3,14 +3,14 @@ #include "base/buffer_vector.hpp" #include "base/stl_add.hpp" -#include "std/algorithm.hpp" -#include "std/cstdint.hpp" -#include "std/iterator.hpp" -#include "std/limits.hpp" -#include "std/regex.hpp" -#include "std/sstream.hpp" -#include "std/string.hpp" -#include "std/type_traits.hpp" +#include <algorithm> +#include <cstdint> +#include <iterator> +#include <limits> +#include <regex> +#include <sstream> +#include <string> +#include <type_traits> #include "3party/utfcpp/source/utf8/unchecked.h" @@ -63,7 +63,7 @@ void NormalizeInplace(UniString & s); UniString Normalize(UniString const & s); /// Replaces "full width" unicode digits with ascii ones. -void NormalizeDigits(string & utf8); +void NormalizeDigits(std::string & utf8); void NormalizeDigits(UniString & us); /// Counts number of start symbols in string s (that is not lower and not normalized) that maches @@ -72,37 +72,37 @@ void NormalizeDigits(UniString & us); /// For implementation @see base/lower_case.cpp size_t CountNormLowerSymbols(UniString const & s, UniString const & lowStr); -void AsciiToLower(string & s); +void AsciiToLower(std::string & s); // TODO(AlexZ): current boost impl uses default std::locale() to trim. // In general, it does not work for any unicode whitespace except ASCII U+0020 one. -void Trim(string & s); +void Trim(std::string & s); /// Remove any characters that contain in "anyOf" on left and right side of string s -void Trim(string & s, char const * anyOf); +void Trim(std::string & s, char const * anyOf); -void MakeLowerCaseInplace(string & s); -string MakeLowerCase(string const & s); -bool EqualNoCase(string const & s1, string const & s2); +void MakeLowerCaseInplace(std::string & s); +std::string MakeLowerCase(std::string const & s); +bool EqualNoCase(std::string const & s1, std::string const & s2); -UniString MakeUniString(string const & utf8s); -string ToUtf8(UniString const & s); -bool IsASCIIString(string const & str); +UniString MakeUniString(std::string const & utf8s); +std::string ToUtf8(UniString const & s); +bool IsASCIIString(std::string const & str); bool IsASCIIDigit(UniChar c); bool IsASCIILatin(UniChar c); -inline string DebugPrint(UniString const & s) { return ToUtf8(s); } +inline std::string DebugPrint(UniString const & s) { return ToUtf8(s); } template <typename TDelimFn, typename TIt = UniString::const_iterator, bool KeepEmptyTokens = false> class TokenizeIterator { public: using difference_type = std::ptrdiff_t; - using value_type = string; + using value_type = std::string; using pointer = void; - using reference = string; + using reference = std::string; using iterator_category = std::input_iterator_tag; // *NOTE* |s| must be not temporary! - TokenizeIterator(string const & s, TDelimFn const & delimFn) + TokenizeIterator(std::string const & s, TDelimFn const & delimFn) : m_start(s.begin()), m_end(s.begin()), m_finish(s.end()), m_delimFn(delimFn) { Move(); @@ -115,10 +115,10 @@ public: Move(); } - string operator*() const + std::string operator*() const { ASSERT(m_start != m_finish, ("Dereferencing of empty iterator.")); - return string(m_start.base(), m_end.base()); + return std::string(m_start.base(), m_end.base()); } UniString GetUniString() const @@ -181,13 +181,13 @@ class TokenizeIterator<TDelimFn, TIt, true /* KeepEmptyTokens */> { public: using difference_type = std::ptrdiff_t; - using value_type = string; + using value_type = std::string; using pointer = void; - using reference = string; + using reference = std::string; using iterator_category = std::input_iterator_tag; // *NOTE* |s| must be not temporary! - TokenizeIterator(string const & s, TDelimFn const & delimFn) + TokenizeIterator(std::string const & s, TDelimFn const & delimFn) : m_start(s.begin()), m_end(s.begin()), m_finish(s.end()), m_delimFn(delimFn), m_finished(false) { while (m_end != m_finish && !m_delimFn(*m_end)) @@ -202,10 +202,10 @@ public: ++m_end; } - string operator*() const + std::string operator*() const { ASSERT(!m_finished, ("Dereferencing of empty iterator.")); - return string(m_start.base(), m_end.base()); + return std::string(m_start.base(), m_end.base()); } UniString GetUniString() const @@ -291,14 +291,14 @@ public: }; using SimpleTokenizer = - TokenizeIterator<SimpleDelimiter, ::utf8::unchecked::iterator<string::const_iterator>, + TokenizeIterator<SimpleDelimiter, ::utf8::unchecked::iterator<std::string::const_iterator>, false /* KeepEmptyTokens */>; using SimpleTokenizerWithEmptyTokens = - TokenizeIterator<SimpleDelimiter, ::utf8::unchecked::iterator<string::const_iterator>, + TokenizeIterator<SimpleDelimiter, ::utf8::unchecked::iterator<std::string::const_iterator>, true /* KeepEmptyTokens */>; template <typename TFunctor> -void Tokenize(string const & str, char const * delims, TFunctor && f) +void Tokenize(std::string const & str, char const * delims, TFunctor && f) { SimpleTokenizer iter(str, delims); while (iter) @@ -308,23 +308,23 @@ void Tokenize(string const & str, char const * delims, TFunctor && f) } } -template <template <typename ...> class Collection = vector> -Collection<string> Tokenize(string const & str, char const * delims) +template <template <typename ...> class Collection = std::vector> +Collection<std::string> Tokenize(std::string const & str, char const * delims) { - Collection<string> c; + Collection<std::string> c; Tokenize(str, delims, MakeInsertFunctor(c)); return c; } -static_assert(is_same<vector<string>, decltype(strings::Tokenize("", ""))>::value, +static_assert(std::is_same<std::vector<std::string>, decltype(strings::Tokenize("", ""))>::value, "Tokenize() should return vector<string> by default."); /// Splits a string by the delimiter, keeps empty parts, on an empty string returns an empty vector. /// Does not support quoted columns, newlines in columns and escaped quotes. -void ParseCSVRow(string const & s, char const delimiter, vector<string> & target); +void ParseCSVRow(std::string const & s, char const delimiter, std::vector<std::string> & target); /// @return code of last symbol in string or 0 if s is empty -UniChar LastUniChar(string const & s); +UniChar LastUniChar(std::string const & s); template <class T, size_t N, class TT> bool IsInArray(T(&arr)[N], TT const & t) @@ -344,31 +344,31 @@ bool to_int64(char const * s, int64_t & i); bool to_float(char const * s, float & f); bool to_double(char const * s, double & d); -inline bool is_number(string const & s) +inline bool is_number(std::string const & s) { int64_t dummy; return to_int64(s.c_str(), dummy); } -inline bool to_int(string const & s, int & i, int base = 10) { return to_int(s.c_str(), i, base); } -inline bool to_uint(string const & s, unsigned int & i, int base = 10) +inline bool to_int(std::string const & s, int & i, int base = 10) { return to_int(s.c_str(), i, base); } +inline bool to_uint(std::string const & s, unsigned int & i, int base = 10) { return to_uint(s.c_str(), i, base); } -inline bool to_uint64(string const & s, uint64_t & i) { return to_uint64(s.c_str(), i); } -inline bool to_int64(string const & s, int64_t & i) { return to_int64(s.c_str(), i); } -inline bool to_float(string const & s, float & f) { return to_float(s.c_str(), f); } -inline bool to_double(string const & s, double & d) { return to_double(s.c_str(), d); } +inline bool to_uint64(std::string const & s, uint64_t & i) { return to_uint64(s.c_str(), i); } +inline bool to_int64(std::string const & s, int64_t & i) { return to_int64(s.c_str(), i); } +inline bool to_float(std::string const & s, float & f) { return to_float(s.c_str(), f); } +inline bool to_double(std::string const & s, double & d) { return to_double(s.c_str(), d); } //@} /// @name From numeric to string. //@{ -inline string to_string(string const & s) { return s; } -inline string to_string(char const * s) { return s; } +inline std::string to_string(std::string const & s) { return s; } +inline std::string to_string(char const * s) { return s; } template <typename T> -string to_string(T t) +std::string to_string(T t) { - ostringstream ss; + std::ostringstream ss; ss << t; return ss.str(); } @@ -389,7 +389,7 @@ int UpperBoundOnChars() // // NOTE: following code works only on two-complement systems! - return numeric_limits<T>::digits10 + is_signed<T>::value + 1; + return std::numeric_limits<T>::digits10 + std::is_signed<T>::value + 1; } template <typename T> @@ -405,7 +405,7 @@ char * to_string_digits(char * buf, T i) } template <typename T> -string to_string_signed(T i) +std::string to_string_signed(T i) { bool const negative = i < 0; int const sz = UpperBoundOnChars<T>(); @@ -417,41 +417,41 @@ string to_string_signed(T i) --beg; *beg = '-'; } - return string(beg, end - beg); + return std::string(beg, end - beg); } template <typename T> -string to_string_unsigned(T i) +std::string to_string_unsigned(T i) { int const sz = UpperBoundOnChars<T>(); char buf[sz]; char * end = buf + sz; char * beg = to_string_digits(end, i); - return string(beg, end - beg); + return std::string(beg, end - beg); } } -inline string to_string(int64_t i) { return impl::to_string_signed(i); } -inline string to_string(uint64_t i) { return impl::to_string_unsigned(i); } +inline std::string to_string(int64_t i) { return impl::to_string_signed(i); } +inline std::string to_string(uint64_t i) { return impl::to_string_unsigned(i); } /// Use this function to get string with fixed count of /// "Digits after comma". -string to_string_dac(double d, int dac); -inline string to_string_with_digits_after_comma(double d, int dac) { return to_string_dac(d, dac); } +std::string to_string_dac(double d, int dac); +inline std::string to_string_with_digits_after_comma(double d, int dac) { return to_string_dac(d, dac); } //@} bool StartsWith(UniString const & s, UniString const & p); -bool StartsWith(string const & s1, char const * s2); +bool StartsWith(std::string const & s1, char const * s2); -bool EndsWith(string const & s1, char const * s2); +bool EndsWith(std::string const & s1, char const * s2); -bool EndsWith(string const & s1, string const & s2); +bool EndsWith(std::string const & s1, std::string const & s2); /// Try to guess if it's HTML or not. No guarantee. -bool IsHTML(string const & utf8); +bool IsHTML(std::string const & utf8); /// Compare str1 and str2 and return if they are equal except for mismatchedSymbolsNum symbols -bool AlmostEqual(string const & str1, string const & str2, size_t mismatchedCount); +bool AlmostEqual(std::string const & str1, std::string const & str2, size_t mismatchedCount); template <typename TIterator, typename TDelimiter> typename TIterator::value_type JoinStrings(TIterator begin, TIterator end, @@ -478,9 +478,9 @@ typename TContainer::value_type JoinStrings(TContainer const & container, } template <typename TFn> -void ForEachMatched(string const & s, regex const & regex, TFn && fn) +void ForEachMatched(std::string const & s, std::regex const & regex, TFn && fn) { - for (sregex_token_iterator cur(s.begin(), s.end(), regex), end; cur != end; ++cur) + for (std::sregex_token_iterator cur(s.begin(), s.end(), regex), end; cur != end; ++cur) fn(*cur); } @@ -496,16 +496,16 @@ void ForEachMatched(string const & s, regex const & regex, TFn && fn) template <typename TIter> size_t EditDistance(TIter const & b1, TIter const & e1, TIter const & b2, TIter const & e2) { - size_t const n = distance(b1, e1); - size_t const m = distance(b2, e2); + size_t const n = std::distance(b1, e1); + size_t const m = std::distance(b2, e2); if (m > n) return EditDistance(b2, e2, b1, e1); // |curr| and |prev| are current and previous rows of the // dynamic programming table. - vector<size_t> prev(m + 1); - vector<size_t> curr(m + 1); + std::vector<size_t> prev(m + 1); + std::vector<size_t> curr(m + 1); for (size_t j = 0; j <= m; ++j) prev[j] = j; auto it1 = b1; @@ -519,8 +519,8 @@ size_t EditDistance(TIter const & b1, TIter const & e1, TIter const & b2, TIter { auto const & c2 = *it2; - curr[j] = min(curr[j - 1], prev[j]) + 1; - curr[j] = min(curr[j], prev[j - 1] + (c1 == c2 ? 0 : 1)); + curr[j] = std::min(curr[j - 1], prev[j]) + 1; + curr[j] = std::min(curr[j], prev[j - 1] + (c1 == c2 ? 0 : 1)); } prev.swap(curr); } diff --git a/base/strings_bundle.cpp b/base/strings_bundle.cpp index fcfdecb7a8..07fa30ed66 100644 --- a/base/strings_bundle.cpp +++ b/base/strings_bundle.cpp @@ -1,17 +1,17 @@ #include "base/strings_bundle.hpp" -void StringsBundle::SetDefaultString(string const & name, string const & value) +void StringsBundle::SetDefaultString(std::string const & name, std::string const & value) { m_defValues[name] = value; } -void StringsBundle::SetString(string const & name, string const & value) +void StringsBundle::SetString(std::string const & name, std::string const & value) { m_values[name] = value; } -string const StringsBundle::GetString(string const & name) const +std::string const StringsBundle::GetString(std::string const & name) const { TStringMap::const_iterator it = m_values.find(name); if (it != m_values.end()) diff --git a/base/strings_bundle.hpp b/base/strings_bundle.hpp index 5fc90eca04..8cc407bc0b 100644 --- a/base/strings_bundle.hpp +++ b/base/strings_bundle.hpp @@ -1,17 +1,17 @@ #pragma once -#include "std/string.hpp" -#include "std/map.hpp" +#include <string> +#include <map> class StringsBundle { - typedef map<string, string> TStringMap; + using TStringMap = std::map<std::string, std::string>; TStringMap m_values; TStringMap m_defValues; public: - void SetDefaultString(string const & name, string const & value); - void SetString(string const & name, string const & value); - string const GetString(string const & name) const; + void SetDefaultString(std::string const & name, std::string const & value); + void SetString(std::string const & name, std::string const & value); + std::string const GetString(std::string const & name) const; }; diff --git a/base/sunrise_sunset.cpp b/base/sunrise_sunset.cpp index 16e11dd03a..3d8356caae 100644 --- a/base/sunrise_sunset.cpp +++ b/base/sunrise_sunset.cpp @@ -83,7 +83,7 @@ enum class DayEventType // This function was taken from source http://williams.best.vwh.net/sunrise_sunset_algorithm.htm. // Notation is kept to have source close to source. // Original article is // http://babel.hathitrust.org/cgi/pt?id=uiug.30112059294311;view=1up;seq=25 -pair<DayEventType, time_t> CalculateDayEventTime(time_t timeUtc, +std::pair<DayEventType, time_t> CalculateDayEventTime(time_t timeUtc, double latitude, double longitude, bool sunrise) { @@ -155,7 +155,7 @@ pair<DayEventType, time_t> CalculateDayEventTime(time_t timeUtc, int const m = sunrise ? 0 : 59; int const s = sunrise ? 0 : 59; - return make_pair((cosH < -1) ? DayEventType::PolarDay : DayEventType::PolarNight, + return std::make_pair((cosH < -1) ? DayEventType::PolarDay : DayEventType::PolarNight, base::TimeGM(year, month, day, h, m, s)); } @@ -199,7 +199,7 @@ pair<DayEventType, time_t> CalculateDayEventTime(time_t timeUtc, int const m = floor((UT - h) * 60); // [0;60) int const s = fmod(floor(UT * 60 * 60) /* number of seconds from 0:0 to UT */, 60); // [0;60) - return make_pair(sunrise ? DayEventType::Sunrise : DayEventType::Sunset, + return std::make_pair(sunrise ? DayEventType::Sunrise : DayEventType::Sunset, base::TimeGM(year, month, day, h, m, s)); } @@ -242,7 +242,7 @@ DayTimeType GetDayTime(time_t timeUtc, double latitude, double longitude) return DayTimeType::Day; } -string DebugPrint(DayTimeType type) +std::string DebugPrint(DayTimeType type) { switch (type) { @@ -251,5 +251,5 @@ string DebugPrint(DayTimeType type) case DayTimeType::PolarDay: return "PolarDay"; case DayTimeType::PolarNight: return "PolarNight"; } - return string(); + return std::string(); } diff --git a/base/sunrise_sunset.hpp b/base/sunrise_sunset.hpp index 110c9c4151..f748505a64 100644 --- a/base/sunrise_sunset.hpp +++ b/base/sunrise_sunset.hpp @@ -1,7 +1,7 @@ #pragma once -#include "std/ctime.hpp" -#include "std/string.hpp" +#include <ctime> +#include <string> enum class DayTimeType { @@ -11,7 +11,7 @@ enum class DayTimeType PolarNight }; -string DebugPrint(DayTimeType type); +std::string DebugPrint(DayTimeType type); /// Helpers which calculates 'is day time' without a time calculation error. /// @param timeUtc - utc time diff --git a/base/swap.hpp b/base/swap.hpp deleted file mode 100644 index 6d817e3ff6..0000000000 --- a/base/swap.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include "std/algorithm.hpp" - -// Calls swap() function using argument dependant lookup. -// Do NOT override this function, but override swap() function instead! -template <typename T> inline void Swap(T & a, T & b) -{ - using std::swap; - swap(a, b); -} diff --git a/base/thread.cpp b/base/thread.cpp index 2c3bc913e8..6b94df4ce5 100644 --- a/base/thread.cpp +++ b/base/thread.cpp @@ -2,8 +2,8 @@ #include "base/logging.hpp" -#include "std/chrono.hpp" -#include "std/exception.hpp" +#include <chrono> +#include <exception> #if defined(OMIM_OS_ANDROID) void AndroidThreadAttachToJVM(); @@ -15,7 +15,7 @@ namespace threads namespace { /// Prepares worker thread and runs routine. -void RunRoutine(shared_ptr<IRoutine> routine) +void RunRoutine(std::shared_ptr<IRoutine> routine) { #if defined(OMIM_OS_ANDROID) AndroidThreadAttachToJVM(); @@ -47,16 +47,16 @@ Thread::~Thread() m_thread.detach(); } -bool Thread::Create(unique_ptr<IRoutine> && routine) +bool Thread::Create(std::unique_ptr<IRoutine> && routine) { ASSERT(!m_routine, ("Current implementation doesn't allow to reuse thread")); - thread routineThread; + std::thread routineThread; try { m_routine.reset(routine.release()); - routineThread = thread(&RunRoutine, m_routine); + routineThread = std::thread(&RunRoutine, m_routine); } - catch (exception & e) + catch (std::exception & e) { LOG(LERROR, ("Thread creation failed with error:", e.what())); m_routine.reset(); @@ -88,7 +88,7 @@ IRoutine * Thread::GetRoutine() { return m_routine.get(); } SimpleThreadPool::SimpleThreadPool(size_t reserve) { m_pool.reserve(reserve); } -void SimpleThreadPool::Add(unique_ptr<IRoutine> && routine) +void SimpleThreadPool::Add(std::unique_ptr<IRoutine> && routine) { m_pool.emplace_back(new Thread()); m_pool.back()->Create(move(routine)); @@ -102,14 +102,14 @@ void SimpleThreadPool::Join() IRoutine * SimpleThreadPool::GetRoutine(size_t i) const { return m_pool[i]->GetRoutine(); } -void Sleep(size_t ms) { this_thread::sleep_for(milliseconds(ms)); } +void Sleep(size_t ms) { std::this_thread::sleep_for(std::chrono::milliseconds(ms)); } -ThreadID GetCurrentThreadID() { return this_thread::get_id(); } +ThreadID GetCurrentThreadID() { return std::this_thread::get_id(); } ///////////////////////////////////////////////////////////////////// // SimpleThread implementation -void SimpleThread::ThreadFunc(function<void()> && fn) +void SimpleThread::ThreadFunc(std::function<void()> && fn) { #if defined(OMIM_OS_ANDROID) AndroidThreadAttachToJVM(); diff --git a/base/thread.hpp b/base/thread.hpp index c5bc84bcd5..88eb7cdf20 100644 --- a/base/thread.hpp +++ b/base/thread.hpp @@ -4,16 +4,16 @@ #include "base/cancellable.hpp" #include "base/macros.hpp" -#include "std/bind.hpp" -#include "std/cstdint.hpp" -#include "std/function.hpp" -#include "std/noncopyable.hpp" -#include "std/shared_ptr.hpp" #include "std/target_os.hpp" -#include "std/thread.hpp" -#include "std/unique_ptr.hpp" -#include "std/utility.hpp" -#include "std/vector.hpp" + +#include <cstdint> +#include <functional> +#include <memory> +#include <thread> +#include <utility> +#include <vector> + +#include <boost/noncopyable.hpp> #ifdef OMIM_OS_WINDOWS #include "std/windows.hpp" // for DWORD @@ -37,8 +37,8 @@ public: /// IRoutine. class Thread { - thread m_thread; - shared_ptr<IRoutine> m_routine; + std::thread m_thread; + std::shared_ptr<IRoutine> m_routine; DISALLOW_COPY(Thread); @@ -52,7 +52,7 @@ public: /// destroyed by the current Thread instance or by /// the m_thread, if it is detached during the /// execution of routine. - bool Create(unique_ptr<IRoutine> && routine); + bool Create(std::unique_ptr<IRoutine> && routine); /// Calling the IRoutine::Cancel method, and Join'ing with the task /// execution. After that, routine is deleted. @@ -78,14 +78,14 @@ public: }; /// Simple threads container. Takes ownership for every added IRoutine. -class SimpleThreadPool : public noncopyable +class SimpleThreadPool : public boost::noncopyable { - vector<unique_ptr<Thread>> m_pool; + std::vector<std::unique_ptr<Thread>> m_pool; public: SimpleThreadPool(size_t reserve = 0); - void Add(unique_ptr<IRoutine> && routine); + void Add(std::unique_ptr<IRoutine> && routine); void Join(); IRoutine * GetRoutine(size_t i) const; @@ -95,7 +95,7 @@ public: /// @param[in] ms time-out interval in milliseconds void Sleep(size_t ms); -typedef thread::id ThreadID; +using ThreadID = std::thread::id; ThreadID GetCurrentThreadID(); @@ -104,8 +104,8 @@ ThreadID GetCurrentThreadID(); class SimpleThread { public: - using id = thread::id; - using native_handle_type = thread::native_handle_type; + using id = std::thread::id; + using native_handle_type = std::thread::native_handle_type; SimpleThread() noexcept {} SimpleThread(SimpleThread && x) noexcept @@ -114,7 +114,7 @@ public: template <class Fn, class... Args> explicit SimpleThread(Fn && fn, Args &&... args) - : m_thread(&SimpleThread::ThreadFunc, bind(forward<Fn>(fn), forward<Args>(args)...)) + : m_thread(&SimpleThread::ThreadFunc, std::bind(std::forward<Fn>(fn), std::forward<Args>(args)...)) {} SimpleThread & operator= (SimpleThread && x) noexcept @@ -131,10 +131,10 @@ public: void swap(SimpleThread & x) noexcept { m_thread.swap(x.m_thread); } private: - static void ThreadFunc(function<void()> && fn); + static void ThreadFunc(std::function<void()> && fn); DISALLOW_COPY(SimpleThread); - thread m_thread; + std::thread m_thread; }; } // namespace threads diff --git a/base/thread_checker.cpp b/base/thread_checker.cpp index 0a6ea92444..84688b19b8 100644 --- a/base/thread_checker.cpp +++ b/base/thread_checker.cpp @@ -1,5 +1,5 @@ #include "base/thread_checker.hpp" -ThreadChecker::ThreadChecker() : m_id(this_thread::get_id()) {} +ThreadChecker::ThreadChecker() : m_id(std::this_thread::get_id()) {} -bool ThreadChecker::CalledOnOriginalThread() const { return this_thread::get_id() == m_id; } +bool ThreadChecker::CalledOnOriginalThread() const { return std::this_thread::get_id() == m_id; } diff --git a/base/thread_checker.hpp b/base/thread_checker.hpp index e5f44b7486..c4592016ad 100644 --- a/base/thread_checker.hpp +++ b/base/thread_checker.hpp @@ -3,7 +3,7 @@ #include "base/assert.hpp" #include "base/macros.hpp" -#include "std/thread.hpp" +#include <thread> /// This class remembers id of a thread on which it was created, and /// then can be used to verify that CalledOnOriginalThread() is called @@ -18,7 +18,7 @@ public: bool CalledOnOriginalThread() const; private: - thread::id const m_id; + std::thread::id const m_id; DISALLOW_COPY_AND_MOVE(ThreadChecker); }; diff --git a/base/thread_pool.cpp b/base/thread_pool.cpp index 626061fd2b..99952809f0 100644 --- a/base/thread_pool.cpp +++ b/base/thread_pool.cpp @@ -1,17 +1,18 @@ #include "base/thread_pool.hpp" +#include "base/stl_add.hpp" #include "base/thread.hpp" #include "base/threaded_list.hpp" -#include "std/vector.hpp" -#include "std/utility.hpp" -#include "std/bind.hpp" +#include <functional> +#include <utility> +#include <vector> namespace threads { namespace { - typedef function<threads::IRoutine *()> TPopRoutineFn; + typedef std::function<threads::IRoutine *()> TPopRoutineFn; class PoolRoutine : public IRoutine { @@ -53,7 +54,7 @@ namespace threads for (auto & thread : m_threads) { thread.reset(new threads::Thread()); - thread->Create(make_unique<PoolRoutine>(bind(&ThreadPool::Impl::PopFront, this), m_finishFn)); + thread->Create(my::make_unique<PoolRoutine>(std::bind(&ThreadPool::Impl::PopFront, this), m_finishFn)); } } @@ -85,7 +86,7 @@ namespace threads thread->Cancel(); m_threads.clear(); - m_tasks.ProcessList([this](list<threads::IRoutine *> & tasks) + m_tasks.ProcessList([this](std::list<threads::IRoutine *> & tasks) { FinishTasksOnStop(tasks); }); @@ -93,9 +94,9 @@ namespace threads } private: - void FinishTasksOnStop(list<threads::IRoutine *> & tasks) + void FinishTasksOnStop(std::list<threads::IRoutine *> & tasks) { - typedef list<threads::IRoutine *>::iterator task_iter; + typedef std::list<threads::IRoutine *>::iterator task_iter; for (task_iter it = tasks.begin(); it != tasks.end(); ++it) { (*it)->Cancel(); @@ -107,7 +108,7 @@ namespace threads ThreadedList<threads::IRoutine *> m_tasks; TFinishRoutineFn m_finishFn; - vector<unique_ptr<threads::Thread>> m_threads; + std::vector<std::unique_ptr<threads::Thread>> m_threads; }; ThreadPool::ThreadPool(size_t size, const TFinishRoutineFn & finishFn) diff --git a/base/thread_pool.hpp b/base/thread_pool.hpp index 292799b42b..ddd664ae28 100644 --- a/base/thread_pool.hpp +++ b/base/thread_pool.hpp @@ -2,13 +2,13 @@ #include "base/base.hpp" -#include "std/function.hpp" +#include <functional> namespace threads { class IRoutine; - typedef function<void(threads::IRoutine *)> TFinishRoutineFn; + typedef std::function<void(threads::IRoutine *)> TFinishRoutineFn; class ThreadPool { diff --git a/base/threaded_list.hpp b/base/threaded_list.hpp index ee9e5d72e5..4390ed1f6a 100644 --- a/base/threaded_list.hpp +++ b/base/threaded_list.hpp @@ -1,19 +1,19 @@ #pragma once +#include "base/threaded_container.hpp" #include "base/condition.hpp" #include "base/logging.hpp" -#include "std/list.hpp" -#include "base/threaded_container.hpp" +#include <list> template <typename T> class ThreadedList : public ThreadedContainer { private: - list<T> m_list; + std::list<T> m_list; bool m_isEmpty; - string m_resName; + std::string m_resName; public: @@ -69,7 +69,7 @@ public: m_resName = name; } - string const & GetName() const + std::string const & GetName() const { return m_resName; } diff --git a/base/threaded_priority_queue.hpp b/base/threaded_priority_queue.hpp deleted file mode 100644 index 060ca70963..0000000000 --- a/base/threaded_priority_queue.hpp +++ /dev/null @@ -1,83 +0,0 @@ -#pragma once - -#include "base/threaded_container.hpp" -#include "std/queue.hpp" - -template <typename T> -class ThreadedPriorityQueue : public ThreadedContainer -{ -private: - priority_queue<T> m_queue; -public: - - template <typename Fn> - void ProcessQueue(Fn const & fn) - { - threads::ConditionGuard g(m_Cond); - - bool hadElements = !m_queue.empty(); - - fn(m_queue); - - bool hasElements = !m_queue.empty(); - - if (!hadElements && hasElements) - m_Cond.Signal(); - } - - void Push(T const & t) - { - threads::ConditionGuard g(m_Cond); - - bool doSignal = m_queue.empty(); - - m_queue.push(t); - - if (doSignal) - m_Cond.Signal(); - } - - bool WaitNonEmpty() - { - while (m_queue.empty()) - { - if (IsCancelled()) - break; - - m_Cond.Wait(); - } - - if (IsCancelled()) - return true; - - return false; - } - - T Top(bool doPop) - { - threads::ConditionGuard g(m_Cond); - - if (WaitNonEmpty()) - return T(); - - T res = m_queue.top(); - - if (doPop) - m_queue.pop(); - - return res; - } - - bool Empty() const - { - threads::ConditionGuard g(m_Cond); - return m_queue.empty(); - } - - void Clear() - { - threads::ConditionGuard g(m_Cond); - while (!m_queue.empty()) - m_queue.pop(); - } -}; diff --git a/base/time_samples.cpp b/base/time_samples.cpp deleted file mode 100644 index 209385b060..0000000000 --- a/base/time_samples.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "base/time_samples.hpp" - -#include "std/cmath.hpp" - -namespace my -{ -void TimeSamples::Add(double seconds) -{ - m_sum += seconds; - m_sum2 += seconds * seconds; - ++m_total; -} - -double TimeSamples::GetMean() const { return m_total == 0 ? 0.0 : m_sum / m_total; } - -double TimeSamples::GetSD() const -{ - if (m_total < 2) - return 0.0; - return std::max((m_sum2 - m_sum * m_sum / static_cast<double>(m_total)) / (m_total - 1), 0.0); -} - -double TimeSamples::GetVar() const { return sqrt(GetSD()); } -} // namespace my diff --git a/base/time_samples.hpp b/base/time_samples.hpp deleted file mode 100644 index c4f1fdf072..0000000000 --- a/base/time_samples.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include "base/timer.hpp" - -#include "std/cstdint.hpp" - -namespace my -{ -// This class can be used in measurements of code blocks performance. -// It can accumulate time samples, and can calculate mean time and -// standard deviation. -// -// *NOTE* This class is NOT thread-safe. -class TimeSamples final -{ -public: - void Add(double seconds); - - // Mean of the accumulated time samples. - double GetMean() const; - - // Unbiased standard deviation of the accumulated time samples. - double GetSD() const; - - // Unbiased variance of the accumulated time samples. - double GetVar() const; - -private: - double m_sum = 0.0; - double m_sum2 = 0.0; - size_t m_total = 0; -}; - -// This class can be used as a single scoped time sample. It -// automatically adds time sample on destruction. -// -// *NOTE* This class is NOT thread-safe. -class ScopedTimeSample final -{ -public: - ScopedTimeSample(TimeSamples & ts) : m_ts(ts) {} - ~ScopedTimeSample() { m_ts.Add(m_t.ElapsedSeconds()); } - -private: - TimeSamples & m_ts; - my::Timer m_t; -}; - -} // namespace my diff --git a/base/timegm.cpp b/base/timegm.cpp index 659ad067ec..02461d6095 100644 --- a/base/timegm.cpp +++ b/base/timegm.cpp @@ -3,7 +3,7 @@ #include "base/assert.hpp" #include "base/timer.hpp" -#include "std/chrono.hpp" +#include <chrono> // There are issues with this implementation due to absence // of time_t fromat specification. There are no guarantees diff --git a/base/timegm.hpp b/base/timegm.hpp index b5bc0e763d..1b4c27d438 100644 --- a/base/timegm.hpp +++ b/base/timegm.hpp @@ -1,7 +1,7 @@ #pragma once -#include "std/cstdint.hpp" -#include "std/ctime.hpp" +#include <cstdint> +#include <ctime> namespace base { diff --git a/base/timer.cpp b/base/timer.cpp index 60d87ff730..f8796b0479 100644 --- a/base/timer.cpp +++ b/base/timer.cpp @@ -3,14 +3,15 @@ #include "base/timegm.hpp" #include "base/timer.hpp" -#include "std/algorithm.hpp" -#include "std/chrono.hpp" -#include "std/cstdio.hpp" -#include "std/iomanip.hpp" -#include "std/sstream.hpp" #include "std/systime.hpp" #include "std/target_os.hpp" +#include <algorithm> +#include <chrono> +#include <cstdio> +#include <iomanip> +#include <sstream> + namespace my { @@ -38,10 +39,10 @@ double Timer::LocalTime() #endif } -string FormatCurrentTime() +std::string FormatCurrentTime() { time_t t = time(NULL); - string s(ctime(&t)); + std::string s(ctime(&t)); replace(s.begin(), s.end(), ' ', '_'); @@ -63,10 +64,10 @@ uint64_t SecondsSinceEpoch() return TimeTToSecondsSinceEpoch(::time(nullptr)); } -string TimestampToString(time_t time) +std::string TimestampToString(time_t time) { if (time == INVALID_TIME_STAMP) - return string("INVALID_TIME_STAMP"); + return std::string("INVALID_TIME_STAMP"); tm * t = gmtime(&time); char buf[21] = { 0 }; @@ -92,7 +93,7 @@ bool IsValid(tm const & t) } } -time_t StringToTimestamp(string const & s) +time_t StringToTimestamp(std::string const & s) { // Return current time in the case of failure time_t res = INVALID_TIME_STAMP; @@ -101,8 +102,8 @@ time_t StringToTimestamp(string const & s) { // Parse UTC format: 1970-01-01T00:00:00Z tm t{}; - istringstream ss(s); - ss >> get_time(&t, "%Y-%m-%dT%H:%M:%SZ"); + std::istringstream ss(s); + ss >> std::get_time(&t, "%Y-%m-%dT%H:%M:%SZ"); if (!ss.fail() && IsValid(t)) res = base::TimeGM(t); @@ -112,8 +113,8 @@ time_t StringToTimestamp(string const & s) // Parse custom time zone offset format: 2012-12-03T00:38:34+03:30 tm t1{}, t2{}; char sign; - istringstream ss(s); - ss >> get_time(&t1, "%Y-%m-%dT%H:%M:%S") >> sign >> get_time(&t2, "%H:%M"); + std::istringstream ss(s); + ss >> std::get_time(&t1, "%Y-%m-%dT%H:%M:%S") >> sign >> std::get_time(&t2, "%H:%M"); if (!ss.fail() && IsValid(t1)) { @@ -138,33 +139,33 @@ HighResTimer::HighResTimer(bool start/* = true*/) void HighResTimer::Reset() { - m_start = high_resolution_clock::now(); + m_start = std::chrono::high_resolution_clock::now(); } uint64_t HighResTimer::ElapsedNano() const { - return duration_cast<nanoseconds>(high_resolution_clock::now() - m_start).count(); + return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now() - m_start).count(); } uint64_t HighResTimer::ElapsedMillis() const { - return duration_cast<milliseconds>(high_resolution_clock::now() - m_start).count(); + return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - m_start).count(); } double HighResTimer::ElapsedSeconds() const { - return duration_cast<duration<double>>(high_resolution_clock::now() - m_start).count(); + return std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::high_resolution_clock::now() - m_start).count(); } time_t SecondsSinceEpochToTimeT(uint64_t secondsSinceEpoch) { - time_point<system_clock> const tpoint{seconds(secondsSinceEpoch)}; - return system_clock::to_time_t(tpoint); + std::chrono::time_point<std::chrono::system_clock> const tpoint{std::chrono::seconds(secondsSinceEpoch)}; + return std::chrono::system_clock::to_time_t(tpoint); } uint64_t TimeTToSecondsSinceEpoch(time_t time) { - auto const tpoint = system_clock::from_time_t(time); - return duration_cast<seconds>(tpoint.time_since_epoch()).count(); + auto const tpoint = std::chrono::system_clock::from_time_t(time); + return std::chrono::duration_cast<std::chrono::seconds>(tpoint.time_since_epoch()).count(); } } diff --git a/base/timer.hpp b/base/timer.hpp index d64c66a0ac..72992b523d 100644 --- a/base/timer.hpp +++ b/base/timer.hpp @@ -1,9 +1,9 @@ #pragma once -#include "std/chrono.hpp" -#include "std/cstdint.hpp" -#include "std/ctime.hpp" -#include "std/string.hpp" +#include <chrono> +#include <cstdint> +#include <ctime> +#include <string> namespace my { @@ -11,7 +11,7 @@ namespace my /// Cross platform timer class Timer { - steady_clock::time_point m_startTime; + std::chrono::steady_clock::time_point m_startTime; public: explicit Timer(bool start = true); @@ -20,20 +20,20 @@ public: static double LocalTime(); /// @return Elapsed time from start (@see Reset). - inline steady_clock::duration TimeElapsed() const { return steady_clock::now() - m_startTime; } + inline std::chrono::steady_clock::duration TimeElapsed() const { return std::chrono::steady_clock::now() - m_startTime; } template <typename TDuration> inline TDuration TimeElapsedAs() const { - return duration_cast<TDuration>(TimeElapsed()); + return std::chrono::duration_cast<TDuration>(TimeElapsed()); } - inline double ElapsedSeconds() const { return TimeElapsedAs<duration<double>>().count(); } + inline double ElapsedSeconds() const { return TimeElapsedAs<std::chrono::duration<double>>().count(); } - inline void Reset() { m_startTime = steady_clock::now(); } + inline void Reset() { m_startTime = std::chrono::steady_clock::now(); } }; -string FormatCurrentTime(); +std::string FormatCurrentTime(); /// Generates timestamp for a specified day. /// \param year The number of years since 1900. @@ -46,20 +46,20 @@ uint64_t SecondsSinceEpoch(); /// Always creates strings in UTC time: 1997-07-16T07:30:15Z /// Returns empty string on error -string TimestampToString(time_t time); +std::string TimestampToString(time_t time); time_t const INVALID_TIME_STAMP = -1; /// Accepts strings in UTC format: 1997-07-16T07:30:15Z /// And with custom time offset: 1997-07-16T10:30:15+03:00 /// @return INVALID_TIME_STAMP if string is invalid -time_t StringToTimestamp(string const & s); +time_t StringToTimestamp(std::string const & s); /// High resolution timer to use in comparison tests. class HighResTimer { - typedef high_resolution_clock::time_point PointT; + typedef std::chrono::high_resolution_clock::time_point PointT; PointT m_start; public: diff --git a/base/uni_string_dfa.cpp b/base/uni_string_dfa.cpp index 4106bb8717..e4faaf2828 100644 --- a/base/uni_string_dfa.cpp +++ b/base/uni_string_dfa.cpp @@ -32,7 +32,7 @@ UniStringDFA::Iterator & UniStringDFA::Iterator::Move(UniChar c) // UniStringDFA::UniStringDFA ---------------------------------------------------------------------- UniStringDFA::UniStringDFA(UniString const & s) : m_s(s) {} -UniStringDFA::UniStringDFA(string const & s): UniStringDFA(MakeUniString(s)) {} +UniStringDFA::UniStringDFA(std::string const & s): UniStringDFA(MakeUniString(s)) {} UniStringDFA::Iterator UniStringDFA::Begin() const { diff --git a/base/uni_string_dfa.hpp b/base/uni_string_dfa.hpp index f7e75085a1..bd2d2b6bb0 100644 --- a/base/uni_string_dfa.hpp +++ b/base/uni_string_dfa.hpp @@ -3,7 +3,7 @@ #include "base/logging.hpp" #include "base/string_utils.hpp" -#include "std/string.hpp" +#include <string> namespace strings { @@ -29,7 +29,7 @@ public: }; explicit UniStringDFA(UniString const & s); - explicit UniStringDFA(string const & s); + explicit UniStringDFA(std::string const & s); Iterator Begin() const; diff --git a/base/worker_thread.hpp b/base/worker_thread.hpp deleted file mode 100644 index 8f47c8f2ae..0000000000 --- a/base/worker_thread.hpp +++ /dev/null @@ -1,113 +0,0 @@ -#pragma once - -#include "base/assert.hpp" -#include "base/macros.hpp" -#include "base/thread_checker.hpp" - -#include "std/condition_variable.hpp" -#include "std/mutex.hpp" -#include "std/queue.hpp" -#include "std/shared_ptr.hpp" -#include "std/thread.hpp" - - -namespace my -{ -/// This class wraps a sequential worker thread, that performs tasks -/// one-by-one. This class is not thread-safe, so, it should be -/// instantiated, used and destroyed on the same thread. -template <typename Task> -class WorkerThread -{ -public: - WorkerThread(int maxTasks) - : m_maxTasks(maxTasks), m_shouldFinish(false), m_workerThread(&WorkerThread::Worker, this) - { - } - - ~WorkerThread() - { - ASSERT(m_threadChecker.CalledOnOriginalThread(), ()); - if (IsRunning()) - RunUntilIdleAndStop(); - ASSERT(!IsRunning(), ()); - } - - /// Pushes new task into worker thread's queue. If the queue is - /// full, current thread is blocked. - /// - /// \param task A callable object that will be called by worker thread. - void Push(shared_ptr<Task> task) - { - ASSERT(m_threadChecker.CalledOnOriginalThread(), ()); - ASSERT(IsRunning(), ()); - unique_lock<mutex> lock(m_mutex); - m_condNotFull.wait(lock, [this]() - { - return m_tasks.size() < m_maxTasks; - }); - m_tasks.push(task); - m_condNonEmpty.notify_one(); - } - - /// Runs worker thread until it'll become idle. After that, - /// terminates worker thread. - void RunUntilIdleAndStop() - { - ASSERT(m_threadChecker.CalledOnOriginalThread(), ()); - ASSERT(IsRunning(), ()); - { - lock_guard<mutex> lock(m_mutex); - m_shouldFinish = true; - m_condNonEmpty.notify_one(); - } - m_workerThread.join(); - } - - /// \return True if worker thread is running, false otherwise. - inline bool IsRunning() const - { - ASSERT(m_threadChecker.CalledOnOriginalThread(), ()); - return m_workerThread.joinable(); - } - -private: - void Worker() - { - shared_ptr<Task> task; - while (true) - { - { - unique_lock<mutex> lock(m_mutex); - m_condNonEmpty.wait(lock, [this]() - { - return m_shouldFinish || !m_tasks.empty(); - }); - if (m_shouldFinish && m_tasks.empty()) - break; - task = m_tasks.front(); - m_tasks.pop(); - m_condNotFull.notify_one(); - } - (*task)(); - } - } - - /// Maximum number of tasks in the queue. - int const m_maxTasks; - queue<shared_ptr<Task>> m_tasks; - - /// When true, worker thread should finish all tasks in the queue - /// and terminate. - bool m_shouldFinish; - - mutex m_mutex; - condition_variable m_condNotFull; - condition_variable m_condNonEmpty; - thread m_workerThread; -#ifdef DEBUG - ThreadChecker m_threadChecker; -#endif - DISALLOW_COPY_AND_MOVE(WorkerThread); -}; // class WorkerThread -} // namespace my |