From: Utkarsh Singh <utkarsh190601@gmail.com>
To: 46301@debbugs.gnu.org
Subject: bug#46301: 28.0.50; cc-mode: add support for c++ lambda expression
Date: Thu, 04 Feb 2021 21:17:22 +0530 [thread overview]
Message-ID: <87czxfx2b9.fsf@gmail.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 1277 bytes --]
Hi,
This bugs only occurs when we assign lambda expression as default
arguments in C++. I know there are better ways of using lambda but I
was just playing with both C++ and Emacs on a hobby project.
Consider this C++ code:
template <typename T>
void bubble_sort(std :: vector<T> &v, bool cmp(T, T)=[](T a, T b){return a < b;})
{
bool swapped = true;
for(size_t i = 0; i < v.size() && swapped; i++) {
swapped = false;
for(size_t j = 0; j < v.size()-i; j++){
if(cmp(v[j+1], v[j])) {
std::swap(v[j], v[j+1]);
swapped=true;
}
}
}
}
Here cmp takes a lambda as default argument and if in c++-mode if we try
using C-M-e(c-end-of-defun) it will get trapped into lambda.
To solve this is added c-forward-to-nth
((memq where '(at-function-end outwith-function at-header in-header))
(when (c-syntactic-re-search-forward "{" nil 'eob)
(backward-char)
(forward-sexp)
;; continue to move sexp if we are looking ) and ,
(while (looking-at ")\\|,")
(c-syntactic-re-search-forward "{" nil 'eob)
(backward-char)
(forward-sexp))
(setq n (1- n))))
By this I am trying to move forward lambda's which are separated by ','
or ended with ')'. I will also attaching the necessary diff to support
the issue.
--
Utkarsh Singh
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: support c++ lambda --]
[-- Type: text/x-patch, Size: 150 bytes --]
1970a1971,1976
>
> (while (looking-at ")\\|,")
> (c-syntactic-re-search-forward "{" nil 'eob)
> (backward-char)
> (forward-sexp))
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 519 bytes --]
next reply other threads:[~2021-02-04 15:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-04 15:47 Utkarsh Singh [this message]
2021-02-23 19:19 ` bug#46301: 28.0.50; cc-mode: add support for c++ lambda expression Alan Mackenzie
2021-02-24 4:07 ` Utkarsh Singh
2021-02-25 20:51 ` Alan Mackenzie
2021-02-27 15:47 ` Utkarsh Singh
2021-03-01 19:34 ` Alan Mackenzie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87czxfx2b9.fsf@gmail.com \
--to=utkarsh190601@gmail.com \
--cc=46301@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).