From 5cc7cb1d85b21a5e50631b032501d8a41f970ad3 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 27 Sep 2017 21:29:13 +0300 Subject: [PATCH] Allow empty arg list in rpl next/error handlers. --- .../SourceFiles/boxes/edit_privacy_box.cpp | 2 +- .../SourceFiles/boxes/notifications_box.cpp | 2 +- Telegram/SourceFiles/boxes/peer_list_box.cpp | 2 +- Telegram/SourceFiles/boxes/stickers_box.cpp | 2 +- .../SourceFiles/chat_helpers/tabbed_panel.cpp | 2 +- .../chat_helpers/tabbed_selector.cpp | 2 +- Telegram/SourceFiles/info/info_layer_wrap.cpp | 2 +- .../SourceFiles/info/info_narrow_wrap.cpp | 2 +- Telegram/SourceFiles/info/info_top_bar.cpp | 2 +- .../info/profile/info_profile_button.cpp | 2 +- .../info/profile/info_profile_cover.cpp | 6 +-- .../info/profile/info_profile_icon.cpp | 2 +- .../profile/info_profile_inner_widget.cpp | 14 +++---- .../info/profile/info_profile_members.cpp | 8 ++-- .../info/profile/info_profile_values.cpp | 24 +++++------ Telegram/SourceFiles/lang/lang_instance.cpp | 2 +- Telegram/SourceFiles/mainwidget.cpp | 2 +- Telegram/SourceFiles/rpl/details/callable.h | 41 ++++++++++++++++--- .../settings/settings_scale_widget.cpp | 2 +- .../SourceFiles/ui/wrap/vertical_layout.cpp | 2 +- .../SourceFiles/window/top_bar_widget.cpp | 2 +- 21 files changed, 78 insertions(+), 47 deletions(-) diff --git a/Telegram/SourceFiles/boxes/edit_privacy_box.cpp b/Telegram/SourceFiles/boxes/edit_privacy_box.cpp index c3bca0bcdb..709185e2d5 100644 --- a/Telegram/SourceFiles/boxes/edit_privacy_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_privacy_box.cpp @@ -288,7 +288,7 @@ void EditPrivacyBox::createWidgets() { auto createExceptionLink = [this](Exception exception) { exceptionLink(exception).create(this, object_ptr(this, exceptionLinkText(exception)), exceptionLinkMargins()); exceptionLink(exception)->heightValue() - | rpl::start_with_next([this](int) { + | rpl::start_with_next([this] { resizeToWidth(width()); }, lifetime()); exceptionLink(exception)->entity()->setClickedCallback([this, exception] { editExceptionUsers(exception); }); diff --git a/Telegram/SourceFiles/boxes/notifications_box.cpp b/Telegram/SourceFiles/boxes/notifications_box.cpp index 6457a8531b..f24f4d5964 100644 --- a/Telegram/SourceFiles/boxes/notifications_box.cpp +++ b/Telegram/SourceFiles/boxes/notifications_box.cpp @@ -129,7 +129,7 @@ void NotificationsBox::prepare() { _countSlider->setActiveSectionFast(_oldCount - 1); _countSlider->sectionActivated() | rpl::start_with_next( - [this](int) { countChanged(); }, + [this] { countChanged(); }, lifetime()); setMouseTracking(true); diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index 027711b120..751a56fcdf 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -52,7 +52,7 @@ void PeerListBox::createMultiSelect() { _select.create(this, std::move(entity)); _select->heightValue() | rpl::start_with_next( - [this](int) { updateScrollSkips(); }, + [this] { updateScrollSkips(); }, lifetime()); _select->entity()->setSubmittedCallback([this](bool chtrlShiftEnter) { content()->submitted(); }); _select->entity()->setQueryChangedCallback([this](const QString &query) { searchQueryChanged(query); }); diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index f6354ec4e5..b357923914 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -246,7 +246,7 @@ void StickersBox::prepare() { setNoContentMargin(true); _tabs->sectionActivated() | rpl::start_with_next( - [this](int) { switchTab(); }, + [this] { switchTab(); }, lifetime()); refreshTabs(); } diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp index 1a173d6e71..8107d47a2b 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp @@ -63,7 +63,7 @@ TabbedPanel::TabbedPanel( } }); _selector->showRequests() - | rpl::start_with_next([this](auto&&) { + | rpl::start_with_next([this] { this->showFromSelector(); }, lifetime()); diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp index 710b0cc7d0..557a868df2 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp @@ -609,7 +609,7 @@ void TabbedSelector::createTabsSlider() { _tabsSlider->setActiveSectionFast(static_cast(_currentTabType)); _tabsSlider->sectionActivated() | rpl::start_with_next( - [this](int) { switchTab(); }, + [this] { switchTab(); }, lifetime()); _tabsSlider->resizeToWidth(width()); diff --git a/Telegram/SourceFiles/info/info_layer_wrap.cpp b/Telegram/SourceFiles/info/info_layer_wrap.cpp index 52f8035dc0..71256eb219 100644 --- a/Telegram/SourceFiles/info/info_layer_wrap.cpp +++ b/Telegram/SourceFiles/info/info_layer_wrap.cpp @@ -81,7 +81,7 @@ object_ptr LayerWrap::createTopBar() { result.data(), st::infoLayerTopBarClose)); close->clicks() - | rpl::start_with_next([this](auto&&) { + | rpl::start_with_next([this] { _controller->hideSpecialLayer(); }, close->lifetime()); result->setTitle(TitleValue( diff --git a/Telegram/SourceFiles/info/info_narrow_wrap.cpp b/Telegram/SourceFiles/info/info_narrow_wrap.cpp index fe1c8967be..c90e513398 100644 --- a/Telegram/SourceFiles/info/info_narrow_wrap.cpp +++ b/Telegram/SourceFiles/info/info_narrow_wrap.cpp @@ -94,7 +94,7 @@ object_ptr NarrowWrap::createTopBar() { st::infoLayerTopBar); result->enableBackButton(true); result->backRequest() - | rpl::start_with_next([this](auto&&) { + | rpl::start_with_next([this] { this->controller()->showBackFromStack(); }, result->lifetime()); result->setTitle(TitleValue( diff --git a/Telegram/SourceFiles/info/info_top_bar.cpp b/Telegram/SourceFiles/info/info_top_bar.cpp index d5bdc9bb00..2ec8c30710 100644 --- a/Telegram/SourceFiles/info/info_top_bar.cpp +++ b/Telegram/SourceFiles/info/info_top_bar.cpp @@ -58,7 +58,7 @@ void TopBar::pushButton(object_ptr button) { auto weak = Ui::AttachParentChild(this, button); _buttons.push_back(std::move(button)); weak->widthValue() - | rpl::start_with_next([this](auto&&) { + | rpl::start_with_next([this] { this->updateControlsGeometry(this->width()); }, _lifetime); } diff --git a/Telegram/SourceFiles/info/profile/info_profile_button.cpp b/Telegram/SourceFiles/info/profile/info_profile_button.cpp index 8af671d4be..1ccc56bdfd 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_button.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_button.cpp @@ -52,7 +52,7 @@ Button *Button::toggleOn(rpl::producer &&toggled) { false, [this] { rtlupdate(toggleRect()); }); clicks() - | rpl::start_with_next([this](auto) { + | rpl::start_with_next([this] { _toggle->setCheckedAnimated(!_toggle->checked()); }, lifetime()); std::move(toggled) diff --git a/Telegram/SourceFiles/info/profile/info_profile_cover.cpp b/Telegram/SourceFiles/info/profile/info_profile_cover.cpp index d30d6d7469..25e0133514 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_cover.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_cover.cpp @@ -254,16 +254,16 @@ void Cover::initViewers() { using Flag = Notify::PeerUpdate::Flag; PeerUpdateValue(_peer, Flag::PhotoChanged) | rpl::start_with_next( - [this](auto&&) { this->refreshUserpicLink(); }, + [this] { this->refreshUserpicLink(); }, lifetime()); PeerUpdateValue(_peer, Flag::NameChanged) | rpl::start_with_next( - [this](auto&&) { this->refreshNameText(); }, + [this] { this->refreshNameText(); }, lifetime()); PeerUpdateValue(_peer, Flag::UserOnlineChanged | Flag::MembersChanged) | rpl::start_with_next( - [this](auto&&) { this->refreshStatusText(); }, + [this] { this->refreshStatusText(); }, lifetime()); } diff --git a/Telegram/SourceFiles/info/profile/info_profile_icon.cpp b/Telegram/SourceFiles/info/profile/info_profile_icon.cpp index 27571d1026..e51c510b69 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_icon.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_icon.cpp @@ -44,7 +44,7 @@ FloatingIcon::FloatingIcon( setAttribute(Qt::WA_TransparentForMouseEvents); parent->widthValue() | rpl::start_with_next( - [this](auto&&) { moveToLeft(0, 0); }, + [this] { moveToLeft(0, 0); }, lifetime()); } diff --git a/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp b/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp index a3adec29f1..d1cab14968 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp @@ -203,7 +203,7 @@ object_ptr InnerWidget::setupMuteToggle( result->toggleOn( NotificationsEnabledValue(_peer) )->clicks() - | rpl::start_with_next([this](auto) { + | rpl::start_with_next([this] { App::main()->updateNotifySetting( _peer, _peer->isMuted() @@ -239,7 +239,7 @@ void InnerWidget::setupUserButtons( _controller->historyPeer.value() | rpl::map($1 != user) )->entity()->clicks() - | rpl::start_with_next([this, user](auto&&) { + | rpl::start_with_next([this, user] { _controller->showPeerHistory( user, Ui::ShowWay::Forward); @@ -250,7 +250,7 @@ void InnerWidget::setupUserButtons( )->toggleOn( CanAddContactValue(user) )->entity()->clicks() - | rpl::start_with_next([user](auto&&) { + | rpl::start_with_next([user] { auto firstName = user->firstName; auto lastName = user->lastName; auto phone = user->phone().isEmpty() @@ -310,7 +310,7 @@ object_ptr InnerWidget::setupSharedMedia( return phrase(lt_count, count); } )->entity()->clicks() - | rpl::start_with_next([peer = _peer, type](auto&&) { + | rpl::start_with_next([peer = _peer, type] { SharedMediaShowOverview(type, App::history(peer)); }, content->lifetime()); }; @@ -321,7 +321,7 @@ object_ptr InnerWidget::setupSharedMedia( return lng_profile_common_groups(lt_count, count); } )->entity()->clicks() - | rpl::start_with_next([peer = _peer](auto&&) { + | rpl::start_with_next([peer = _peer] { App::main()->showSection( ::Profile::CommonGroups::SectionMemento( peer->asUser()), @@ -389,7 +389,7 @@ object_ptr InnerWidget::setupUserActions( )->toggleOn( std::move(toggleOn) )->entity()->clicks() - | rpl::start_with_next([callback = std::move(callback)](auto&&) { + | rpl::start_with_next([callback = std::move(callback)] { callback(); }, result->lifetime()); }; @@ -432,7 +432,7 @@ object_ptr InnerWidget::setupUserActions( st::infoBlockButtonSkip)); auto text = PeerUpdateValue(user, Notify::PeerUpdate::Flag::UserIsBlocked) - | rpl::map([user](auto&&) -> rpl::producer { + | rpl::map([user]() -> rpl::producer { switch (user->blockStatus()) { case UserData::BlockStatus::Blocked: return Lang::Viewer(lng_profile_unblock_user); diff --git a/Telegram/SourceFiles/info/profile/info_profile_members.cpp b/Telegram/SourceFiles/info/profile/info_profile_members.cpp index 6a9d28309a..9c8ef951a0 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_members.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_members.cpp @@ -118,7 +118,7 @@ void Members::setupButtons() { }, _addMember->lifetime()); _addMember->showOn(rpl::duplicate(addMemberShown)); _addMember->clicks() // TODO throttle(ripple duration) - | rpl::start_with_next([this](auto&&) { + | rpl::start_with_next([this] { this->addMember(); }, _addMember->lifetime()); @@ -128,18 +128,18 @@ void Members::setupButtons() { | rpl::start_spawning(lifetime()); _search->showOn(rpl::duplicate(searchShown)); _search->clicks() - | rpl::start_with_next([this](auto&&) { + | rpl::start_with_next([this] { this->showSearch(); }, _search->lifetime()); _cancelSearch->clicks() - | rpl::start_with_next([this](auto&&) { + | rpl::start_with_next([this] { this->cancelSearch(); }, _cancelSearch->lifetime()); rpl::combine( std::move(addMemberShown), std::move(searchShown)) - | rpl::start_with_next([this](auto&&) { + | rpl::start_with_next([this] { this->resizeToWidth(width()); }, lifetime()); diff --git a/Telegram/SourceFiles/info/profile/info_profile_values.cpp b/Telegram/SourceFiles/info/profile/info_profile_values.cpp index f9f036e013..6bb33bd842 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_values.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_values.cpp @@ -68,7 +68,7 @@ rpl::producer PhoneValue( return PeerUpdateValue( user, Notify::PeerUpdate::Flag::UserPhoneChanged) - | rpl::map([user](auto&&) { + | rpl::map([user] { return App::formatPhone(user->phone()); }) | WithEmptyEntities(); @@ -79,7 +79,7 @@ rpl::producer BioValue( return PeerUpdateValue( user, Notify::PeerUpdate::Flag::AboutChanged) - | rpl::map([user](auto&&) { return user->about(); }) + | rpl::map([user] { return user->about(); }) | WithEmptyEntities(); } @@ -88,7 +88,7 @@ rpl::producer PlainUsernameViewer( return PeerUpdateValue( peer, Notify::PeerUpdate::Flag::UsernameChanged) - | rpl::map([peer](auto&&) { + | rpl::map([peer] { return peer->userName(); }); } @@ -110,7 +110,7 @@ rpl::producer AboutValue( return PeerUpdateValue( channel, Notify::PeerUpdate::Flag::AboutChanged) - | rpl::map([channel](auto&&) { return channel->about(); }) + | rpl::map([channel] { return channel->about(); }) | WithEmptyEntities(); } return rpl::single(TextWithEntities{}); @@ -132,7 +132,7 @@ rpl::producer NotificationsEnabledValue( return PeerUpdateValue( peer, Notify::PeerUpdate::Flag::NotificationsEnabled) - | rpl::map([peer](auto&&) { return !peer->isMuted(); }); + | rpl::map([peer] { return !peer->isMuted(); }); } rpl::producer IsContactValue( @@ -140,7 +140,7 @@ rpl::producer IsContactValue( return PeerUpdateValue( user, Notify::PeerUpdate::Flag::UserIsContact) - | rpl::map([user](auto&&) { return user->isContact(); }); + | rpl::map([user] { return user->isContact(); }); } rpl::producer CanShareContactValue( @@ -148,7 +148,7 @@ rpl::producer CanShareContactValue( return PeerUpdateValue( user, Notify::PeerUpdate::Flag::UserCanShareContact) - | rpl::map([user](auto&&) { + | rpl::map([user] { return user->canShareThisContact(); }); } @@ -168,7 +168,7 @@ rpl::producer MembersCountValue( return PeerUpdateValue( peer, Notify::PeerUpdate::Flag::MembersChanged) - | rpl::map([chat](auto&&) { + | rpl::map([chat] { return chat->amIn() ? qMax(chat->count, chat->participants.size()) : 0; @@ -177,7 +177,7 @@ rpl::producer MembersCountValue( return PeerUpdateValue( peer, Notify::PeerUpdate::Flag::MembersChanged) - | rpl::map([channel](auto &&) { + | rpl::map([channel] { auto canViewCount = channel->canViewMembers() || !channel->isMegagroup(); return canViewCount @@ -215,7 +215,7 @@ rpl::producer CommonGroupsCountValue( return PeerUpdateValue( user, Notify::PeerUpdate::Flag::UserCommonChatsChanged) - | rpl::map([user](auto&&) { + | rpl::map([user] { return user->commonChatsCount(); }); } @@ -226,14 +226,14 @@ rpl::producer CanAddMemberValue( return PeerUpdateValue( chat, Notify::PeerUpdate::Flag::ChatCanEdit) - | rpl::map([chat](auto&&) { + | rpl::map([chat] { return chat->canEdit(); }); } else if (auto channel = peer->asChannel()) { return PeerUpdateValue( channel, Notify::PeerUpdate::Flag::ChannelRightsChanged) - | rpl::map([channel](auto&&) { + | rpl::map([channel] { return channel->canAddMembers(); }); } diff --git a/Telegram/SourceFiles/lang/lang_instance.cpp b/Telegram/SourceFiles/lang/lang_instance.cpp index 850202edfc..6276bb9f5b 100644 --- a/Telegram/SourceFiles/lang/lang_instance.cpp +++ b/Telegram/SourceFiles/lang/lang_instance.cpp @@ -504,7 +504,7 @@ rpl::producer Viewer(LangKey key) { rpl::single(Current().getValue(key)) | then( base::ObservableViewer(Current().updated()) - | rpl::map([=](auto&&) { + | rpl::map([=] { return Current().getValue(key); })); } diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 48409cfab0..d3087699b4 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -1847,7 +1847,7 @@ void MainWidget::createPlayer() { _player.create(this); _player->heightValue() | rpl::start_with_next( - [this](int) { playerHeightUpdated(); }, + [this] { playerHeightUpdated(); }, lifetime()); _player->entity()->setCloseCallback([this] { closeBothPlayers(); }); _playerVolume.create(this); diff --git a/Telegram/SourceFiles/rpl/details/callable.h b/Telegram/SourceFiles/rpl/details/callable.h index d1f4e90535..40807eaa21 100644 --- a/Telegram/SourceFiles/rpl/details/callable.h +++ b/Telegram/SourceFiles/rpl/details/callable.h @@ -91,31 +91,62 @@ struct is_callable template struct is_callable : std::bool_constant< - is_callable_plain_v - || is_callable_tuple_v> { + is_callable_plain_v || + is_callable_tuple_v || + is_callable_plain_v> { }; template constexpr bool is_callable_v = is_callable::value; +enum class CallableArgTag { + Plain, + Tuple, + Empty, +}; +template +using callable_arg_tag = std::integral_constant; + template -inline decltype(auto) callable_helper(Method &&method, Arg &&arg, std::true_type) { +inline decltype(auto) callable_helper( + Method &&method, + Arg &&arg, + callable_arg_tag) { return std::forward(method)(std::forward(arg)); } template -inline decltype(auto) callable_helper(Method &&method, Arg &&arg, std::false_type) { +inline decltype(auto) callable_helper( + Method &&method, + Arg &&arg, + callable_arg_tag) { return std::apply( std::forward(method), std::forward(arg)); } +template +inline decltype(auto) callable_helper( + Method &&method, + Arg &&, + callable_arg_tag) { + return std::forward(method)(); +} + template inline decltype(auto) callable_invoke(Method &&method, Arg &&arg) { + // #TODO if constexpr + constexpr auto kTag = is_callable_plain_v + ? CallableArgTag::Plain + : is_callable_tuple_v + ? CallableArgTag::Tuple + : is_callable_v + ? CallableArgTag::Empty + : throw "Bad callable_invoke instance."; return callable_helper( std::forward(method), std::forward(arg), - is_callable_plain()); + callable_arg_tag()); } template diff --git a/Telegram/SourceFiles/settings/settings_scale_widget.cpp b/Telegram/SourceFiles/settings/settings_scale_widget.cpp index 2cfe7f78f7..7bfe8dc959 100644 --- a/Telegram/SourceFiles/settings/settings_scale_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_scale_widget.cpp @@ -62,7 +62,7 @@ void ScaleWidget::createControls() { _scale->setActiveSectionFast(cEvalScale(cConfigScale()) - 1); _scale->sectionActivated() | rpl::start_with_next( - [this](int) { scaleChanged(); }, + [this] { scaleChanged(); }, lifetime()); } diff --git a/Telegram/SourceFiles/ui/wrap/vertical_layout.cpp b/Telegram/SourceFiles/ui/wrap/vertical_layout.cpp index 09114ae16a..383c443435 100644 --- a/Telegram/SourceFiles/ui/wrap/vertical_layout.cpp +++ b/Telegram/SourceFiles/ui/wrap/vertical_layout.cpp @@ -115,7 +115,7 @@ RpWidget *VerticalLayout::addChild( width() - margins.left() - margins.right(), height() - margins.top() - margins.bottom()); weak->heightValue() - | rpl::start_with_next_done([this, weak](int) { + | rpl::start_with_next_done([this, weak] { childHeightUpdated(weak); }, [this, weak] { removeChild(weak); diff --git a/Telegram/SourceFiles/window/top_bar_widget.cpp b/Telegram/SourceFiles/window/top_bar_widget.cpp index 4b885ae53d..0b4b7c97b6 100644 --- a/Telegram/SourceFiles/window/top_bar_widget.cpp +++ b/Telegram/SourceFiles/window/top_bar_widget.cpp @@ -119,7 +119,7 @@ TopBarWidget::TopBarWidget( Auth().data().thirdSectionInfoEnabledValue(), Auth().data().tabbedReplacedWithInfoValue()) | rpl::start_with_next( - [this](auto&&) { updateInfoToggleActive(); }, + [this] { updateInfoToggleActive(); }, lifetime()); setCursor(style::cur_pointer);