From 94e530e0d984d4dd2ab321e5f9e1879bbf42fa1b Mon Sep 17 00:00:00 2001 From: Jiachen YANG Date: Sun, 8 Sep 2019 00:13:40 +0900 Subject: [PATCH 1/8] be compatible with range-v3 0.9.x/1.0 branch This made 2 changes to the current code base to be compatible with higher versions of range-v3 library. 1. ranges::iterator_range was renamed to subrange, see https://github.com/ericniebler/range-v3/issues/766 2. PercentCounterItem need an operator== for ranges::sort for some reason --- Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp | 2 +- Telegram/SourceFiles/data/data_channel.cpp | 2 +- Telegram/SourceFiles/history/history_inner_widget.cpp | 2 +- .../SourceFiles/history/view/media/history_view_poll.cpp | 4 ++++ .../media/streaming/media_streaming_reader.cpp | 8 ++++---- Telegram/SourceFiles/ui/text/text_entity.cpp | 4 ++-- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp b/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp index 7773fd31069d8c..afde3180ce2fbc 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp @@ -449,7 +449,7 @@ std::vector EmojiKeywords::LangPack::query( } const auto from = _data.emoji.lower_bound(normalized); - auto &&chosen = ranges::make_iterator_range( + auto &&chosen = ranges::subrange( from, end(_data.emoji) ) | ranges::view::take_while([&](const auto &pair) { diff --git a/Telegram/SourceFiles/data/data_channel.cpp b/Telegram/SourceFiles/data/data_channel.cpp index e4496e01d3d830..129a7e02895513 100644 --- a/Telegram/SourceFiles/data/data_channel.cpp +++ b/Telegram/SourceFiles/data/data_channel.cpp @@ -764,7 +764,7 @@ void ApplyMegagroupAdmins( } auto adding = base::flat_map(); - auto admins = ranges::make_iterator_range( + auto admins = ranges::subrange( list.begin(), list.end() ) | ranges::view::transform([](const MTPChannelParticipant &p) { const auto userId = p.match([](const auto &data) { diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index abf6b33a763c2d..f485726c9e5459 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2444,7 +2444,7 @@ MessageIdsList HistoryInner::getSelectedItems() const { return {}; } - auto result = make_iterator_range( + auto result = ranges::subrange( _selected.begin(), _selected.end() ) | view::filter([](const auto &selected) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_poll.cpp b/Telegram/SourceFiles/history/view/media/history_view_poll.cpp index 8864401992a300..87e1ca4d03c415 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_poll.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_poll.cpp @@ -34,6 +34,10 @@ struct PercentCounterItem { int percent = 0; int remainder = 0; + inline bool operator==(const PercentCounterItem &o) const { + return remainder == o.remainder && percent == o.percent; + } + inline bool operator<(const PercentCounterItem &other) const { if (remainder > other.remainder) { return true; diff --git a/Telegram/SourceFiles/media/streaming/media_streaming_reader.cpp b/Telegram/SourceFiles/media/streaming/media_streaming_reader.cpp index c1e1705d5e5ecb..4eaf64887a8b42 100644 --- a/Telegram/SourceFiles/media/streaming/media_streaming_reader.cpp +++ b/Telegram/SourceFiles/media/streaming/media_streaming_reader.cpp @@ -291,7 +291,7 @@ auto Reader::Slice::prepareFill(int from, int till) -> PrepareFillResult { ranges::less(), &PartsMap::value_type::first); const auto haveTill = FindNotLoadedStart( - ranges::make_iterator_range(start, finish), + ranges::subrange(start, finish), fromOffset); if (haveTill < till) { result.offsetsFromLoader = offsetsFromLoader( @@ -607,14 +607,14 @@ auto Reader::Slices::fill(int offset, bytes::span buffer) -> FillResult { markSliceUsed(fromSlice); CopyLoaded( buffer, - ranges::make_iterator_range(first.start, first.finish), + ranges::subrange(first.start, first.finish), firstFrom, firstTill); if (fromSlice + 1 < tillSlice) { markSliceUsed(fromSlice + 1); CopyLoaded( buffer.subspan(firstTill - firstFrom), - ranges::make_iterator_range(second.start, second.finish), + ranges::subrange(second.start, second.finish), secondFrom, secondTill); } @@ -644,7 +644,7 @@ auto Reader::Slices::fillFromHeader(int offset, bytes::span buffer) if (prepared.ready) { CopyLoaded( buffer, - ranges::make_iterator_range(prepared.start, prepared.finish), + ranges::subrange(prepared.start, prepared.finish), from, till); result.filled = true; diff --git a/Telegram/SourceFiles/ui/text/text_entity.cpp b/Telegram/SourceFiles/ui/text/text_entity.cpp index 4f3378fcb8181e..0b6a6f71a995cc 100644 --- a/Telegram/SourceFiles/ui/text/text_entity.cpp +++ b/Telegram/SourceFiles/ui/text/text_entity.cpp @@ -1141,7 +1141,7 @@ const QRegularExpression &RegExpWordSplit() { [[nodiscard]] QString ExpandCustomLinks(const TextWithTags &text) { const auto entities = ConvertTextTagsToEntities(text.tags); - auto &&urls = ranges::make_iterator_range( + auto &&urls = ranges::subrange( entities.begin(), entities.end() ) | ranges::view::filter([](const EntityInText &entity) { @@ -2098,7 +2098,7 @@ EntityInText::EntityInText( int EntityInText::FirstMonospaceOffset( const EntitiesInText &entities, int textLength) { - auto &&monospace = ranges::make_iterator_range( + auto &&monospace = ranges::subrange( entities.begin(), entities.end() ) | ranges::view::filter([](const EntityInText & entity) { From bdb0f7a1e2488744e943de66e2a5df2eb10bcb12 Mon Sep 17 00:00:00 2001 From: Jiachen YANG Date: Sun, 8 Sep 2019 00:53:25 +0900 Subject: [PATCH 2/8] Revert "Use 0.5.0 version of range-v3." This reverts commit 3355e6da0c2883f33992c4b2bcac7ce3067a529b. --- .appveyor/install.bat | 5 ++++- .travis/build.sh | 4 ++-- snap/snapcraft.yaml | 1 - 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.appveyor/install.bat b/.appveyor/install.bat index c143e93a24b6a3..c42e30570bfc43 100644 --- a/.appveyor/install.bat +++ b/.appveyor/install.bat @@ -28,7 +28,10 @@ GOTO:EOF git clone -q --depth 1 --branch master https://github.com/telegramdesktop/dependencies_windows.git %LIB_DIR% cd %LIB_DIR% - git clone --depth 1 --branch 0.5.0 https://github.com/ericniebler/range-v3 + git clone https://github.com/ericniebler/range-v3 + cd range-v3 + git checkout 0.5.0 + cd .. if exist prepare.bat ( call prepare.bat diff --git a/.travis/build.sh b/.travis/build.sh index 25daad443ad320..ac04dab4665539 100755 --- a/.travis/build.sh +++ b/.travis/build.sh @@ -28,7 +28,7 @@ GYP_CACHE_VERSION="3" GYP_PATCH="$UPSTREAM/Telegram/Patches/gyp.diff" RANGE_PATH="$BUILD/range-v3" -RANGE_CACHE_VERSION="4" +RANGE_CACHE_VERSION="3" VA_PATH="$BUILD/libva" VA_CACHE_VERSION="3" @@ -217,7 +217,7 @@ buildRange() { rm -rf * cd "$EXTERNAL" - git clone --depth 1 --branch 0.5.0 https://github.com/ericniebler/range-v3 + git clone --depth=1 https://github.com/ericniebler/range-v3 cd "$EXTERNAL/range-v3" cp -r * "$RANGE_PATH/" diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index bc61fef9a19d64..4a4cf5b185cd96 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -393,7 +393,6 @@ parts: range-v3: source: https://github.com/ericniebler/range-v3.git source-depth: 1 - source-tag: 0.5.0 plugin: nil override-build: | set -x From 7f276d872148890a3c2e50abca23e99f5862e7a0 Mon Sep 17 00:00:00 2001 From: Jiachen YANG Date: Tue, 10 Sep 2019 10:14:37 +0900 Subject: [PATCH 3/8] appveyor use range-v3 latest branch --- .appveyor/install.bat | 3 --- 1 file changed, 3 deletions(-) diff --git a/.appveyor/install.bat b/.appveyor/install.bat index c42e30570bfc43..062d87a8561377 100644 --- a/.appveyor/install.bat +++ b/.appveyor/install.bat @@ -29,9 +29,6 @@ GOTO:EOF cd %LIB_DIR% git clone https://github.com/ericniebler/range-v3 - cd range-v3 - git checkout 0.5.0 - cd .. if exist prepare.bat ( call prepare.bat From 330022684554d44a5e673e8c4024b2aa09008c9a Mon Sep 17 00:00:00 2001 From: Jiachen YANG Date: Tue, 10 Sep 2019 10:14:55 +0900 Subject: [PATCH 4/8] include range/v3/range/conversion.hpp instead of range/v3/to_container.hpp --- Telegram/SourceFiles/export/data/export_data_types.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/export/data/export_data_types.cpp b/Telegram/SourceFiles/export/data/export_data_types.cpp index 62a5d47aab42bf..aab49845e4e607 100644 --- a/Telegram/SourceFiles/export/data/export_data_types.cpp +++ b/Telegram/SourceFiles/export/data/export_data_types.cpp @@ -17,7 +17,7 @@ For license and copyright information please follow this link: #include #include #include -#include +#include namespace App { // Hackish.. QString formatPhone(QString phone); From d3d03dd971466e7161959e4778468cd0983a5608 Mon Sep 17 00:00:00 2001 From: Jiachen YANG Date: Tue, 10 Sep 2019 11:03:18 +0900 Subject: [PATCH 5/8] explicitly specify the upper bound in ranges::view::ints --- Telegram/SourceFiles/boxes/single_choice_box.cpp | 2 +- Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp | 4 ++-- Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp | 2 +- Telegram/SourceFiles/history/view/media/history_view_poll.cpp | 2 +- Telegram/SourceFiles/ui/image/image_prepare.cpp | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/boxes/single_choice_box.cpp b/Telegram/SourceFiles/boxes/single_choice_box.cpp index f617a5fcaea3e0..f40c82eefbb955 100644 --- a/Telegram/SourceFiles/boxes/single_choice_box.cpp +++ b/Telegram/SourceFiles/boxes/single_choice_box.cpp @@ -38,7 +38,7 @@ void SingleChoiceBox::prepare() { content->add(object_ptr( content, st::boxOptionListPadding.top() + st::autolockButton.margin.top())); - auto &&ints = ranges::view::ints(0); + auto &&ints = ranges::view::ints(0, ranges::unreachable); for (const auto &[i, text] : ranges::view::zip(ints, _optionTexts)) { content->add( object_ptr( diff --git a/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp b/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp index 09fd1dc95c3628..f3b6635e203b83 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp @@ -367,7 +367,7 @@ void Row::paintPreview(Painter &p) const { const auto y = st::manageEmojiPreviewPadding.top(); const auto width = st::manageEmojiPreviewWidth; const auto height = st::manageEmojiPreviewWidth; - auto &&preview = ranges::view::zip(_preview, ranges::view::ints(0)); + auto &&preview = ranges::view::zip(_preview, ranges::view::ints(0, int(_preview.size()))); for (const auto &[pixmap, index] : preview) { const auto row = (index / 2); const auto column = (index % 2); @@ -570,7 +570,7 @@ void Row::setupPreview(const Set &set) { const auto size = st::manageEmojiPreview * cIntRetinaFactor(); const auto original = QImage(set.previewPath); const auto full = original.height(); - auto &&preview = ranges::view::zip(_preview, ranges::view::ints(0)); + auto &&preview = ranges::view::zip(_preview, ranges::view::ints(0, int(_preview.size()))); for (auto &&[pixmap, index] : preview) { pixmap = App::pixmapFromImageInPlace(original.copy( { full * index, 0, full, full } diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 6f71c940a882f5..a0de1069c6dc8b 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -2962,7 +2962,7 @@ void InnerWidget::setupShortcuts() { Command::ChatPinned4, Command::ChatPinned5, }; - auto &&pinned = ranges::view::zip(kPinned, ranges::view::ints(0)); + auto &&pinned = ranges::view::zip(kPinned, ranges::view::ints(0, ranges::unreachable)); for (const auto [command, index] : pinned) { request->check(command) && request->handle([=, index = index] { const auto list = session().data().chatsList()->indexed(); diff --git a/Telegram/SourceFiles/history/view/media/history_view_poll.cpp b/Telegram/SourceFiles/history/view/media/history_view_poll.cpp index 87e1ca4d03c415..d095ad66166a3c 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_poll.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_poll.cpp @@ -91,7 +91,7 @@ void CountNicePercent( auto &&zipped = ranges::view::zip( votes, items, - ranges::view::ints(0)); + ranges::view::ints(0, int(items.size()))); for (auto &&[votes, item, index] : zipped) { item.index = index; item.percent = (votes * 100) / total; diff --git a/Telegram/SourceFiles/ui/image/image_prepare.cpp b/Telegram/SourceFiles/ui/image/image_prepare.cpp index ea011b0d029d2f..52631dd9379760 100644 --- a/Telegram/SourceFiles/ui/image/image_prepare.cpp +++ b/Telegram/SourceFiles/ui/image/image_prepare.cpp @@ -262,7 +262,7 @@ QImage BlurLargeImage(QImage image, int radius) { const auto dvs = take(dvcount); auto &&ints = ranges::view::ints; - for (auto &&[value, index] : ranges::view::zip(dvs, ints(0))) { + for (auto &&[value, index] : ranges::view::zip(dvs, ints(0, ranges::unreachable))) { value = (index / divsum); } const auto dv = dvs.data(); From cde6b5b7f74d2056e1b94b3f84657e96fe6c33f9 Mon Sep 17 00:00:00 2001 From: Jiachen YANG Date: Tue, 10 Sep 2019 14:40:08 +0900 Subject: [PATCH 6/8] change deprecated ranges::to_ to ranges::to (no underscore) --- Telegram/SourceFiles/ui/grouped_layout.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/ui/grouped_layout.cpp b/Telegram/SourceFiles/ui/grouped_layout.cpp index 8cd1a3bd8b03c8..7b98af8b3c92c8 100644 --- a/Telegram/SourceFiles/ui/grouped_layout.cpp +++ b/Telegram/SourceFiles/ui/grouped_layout.cpp @@ -117,7 +117,7 @@ std::string Layouter::CountProportions(const std::vector &ratios) { ratios ) | ranges::view::transform([](float64 ratio) { return (ratio > 1.2) ? 'w' : (ratio < 0.8) ? 'n' : 'q'; - }) | ranges::to_(); + }) | ranges::to(); } std::vector Layouter::layout() const { From 1be93ecb1c4e41ff0c3e593f3fac85c2a0540988 Mon Sep 17 00:00:00 2001 From: Jiachen YANG Date: Thu, 12 Sep 2019 16:18:06 +0900 Subject: [PATCH 7/8] tweak vs2019 compiler settings to be compatible with newer range-v3 --- Telegram/gyp/common/win.gypi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Telegram/gyp/common/win.gypi b/Telegram/gyp/common/win.gypi index 3d2c779c512ff7..e1d9df16de60da 100644 --- a/Telegram/gyp/common/win.gypi +++ b/Telegram/gyp/common/win.gypi @@ -33,6 +33,8 @@ '/w14834', # [[nodiscard]] '/w15038', # wrong initialization order '/w14265', # class has virtual functions, but destructor is not virtual + '/experimental:preprocessor', # need for range-v3 see https://github.com/ericniebler/range-v3#supported-compilers + '/wd5105', # needed for `/experimental:preprocessor`, suppressing C5105 "macro expansion producing 'defined' has undefined behavior" ], 'TreatWChar_tAsBuiltInType': 'false', }, From 8a59923c16f238e9f914a3d378d092560b7fa983 Mon Sep 17 00:00:00 2001 From: Jiachen YANG Date: Fri, 13 Sep 2019 11:40:40 +0900 Subject: [PATCH 8/8] fix range-v3 version to 0.9.1 --- .appveyor/install.bat | 2 +- .travis/build.sh | 2 +- docs/building-cmake.md | 2 +- docs/building-msvc.md | 2 +- docs/building-xcode.md | 2 +- snap/snapcraft.yaml | 1 + 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.appveyor/install.bat b/.appveyor/install.bat index 062d87a8561377..590d1e0f5734a8 100644 --- a/.appveyor/install.bat +++ b/.appveyor/install.bat @@ -28,7 +28,7 @@ GOTO:EOF git clone -q --depth 1 --branch master https://github.com/telegramdesktop/dependencies_windows.git %LIB_DIR% cd %LIB_DIR% - git clone https://github.com/ericniebler/range-v3 + git clone --depth 1 --branch 0.9.1 https://github.com/ericniebler/range-v3 if exist prepare.bat ( call prepare.bat diff --git a/.travis/build.sh b/.travis/build.sh index ac04dab4665539..4b6d05ff8b2b1e 100755 --- a/.travis/build.sh +++ b/.travis/build.sh @@ -217,7 +217,7 @@ buildRange() { rm -rf * cd "$EXTERNAL" - git clone --depth=1 https://github.com/ericniebler/range-v3 + git clone --depth 1 --branch 0.9.1 https://github.com/ericniebler/range-v3 cd "$EXTERNAL/range-v3" cp -r * "$RANGE_PATH/" diff --git a/docs/building-cmake.md b/docs/building-cmake.md index ce59fd5f7bb562..efc27ec3bf5730 100644 --- a/docs/building-cmake.md +++ b/docs/building-cmake.md @@ -38,7 +38,7 @@ Go to ***BuildPath*** and run mkdir Libraries cd Libraries - git clone --branch 0.5.0 https://github.com/ericniebler/range-v3 + git clone --branch 0.9.1 https://github.com/ericniebler/range-v3 git clone https://github.com/telegramdesktop/zlib.git cd zlib diff --git a/docs/building-msvc.md b/docs/building-msvc.md index f233105c730644..74e513eba38e72 100644 --- a/docs/building-msvc.md +++ b/docs/building-msvc.md @@ -55,7 +55,7 @@ Open **x86 Native Tools Command Prompt for VS 2019.bat**, go to ***BuildPath*** mkdir Libraries cd Libraries - git clone --branch 0.5.0 https://github.com/ericniebler/range-v3 range-v3 + git clone --branch 0.9.1 https://github.com/ericniebler/range-v3 range-v3 git clone https://github.com/telegramdesktop/lzma.git cd lzma\C\Util\LzmaLib diff --git a/docs/building-xcode.md b/docs/building-xcode.md index 90132d1118692e..8dfec18978d0b6 100644 --- a/docs/building-xcode.md +++ b/docs/building-xcode.md @@ -30,7 +30,7 @@ Go to ***BuildPath*** and run cd Libraries - git clone --branch 0.5.0 https://github.com/ericniebler/range-v3 + git clone --branch 0.9.1 https://github.com/ericniebler/range-v3 cd xz-5.0.5 CFLAGS="-mmacosx-version-min=10.8" LDFLAGS="-mmacosx-version-min=10.8" ./configure diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 4a4cf5b185cd96..1adc7047ffdb76 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -393,6 +393,7 @@ parts: range-v3: source: https://github.com/ericniebler/range-v3.git source-depth: 1 + source-tag: 0.9.1 plugin: nil override-build: | set -x